Running the code below in Chrome, in a Vue 3 project with Vite.
const blockHash = await client.waitForTransactionFinalization(tx)
I received the following error:
GRPCClient.js:370 Uncaught (in promise) ReferenceError: setImmediate is not defined
at GRPCClient.js:370:25
Debugging the waitForTransactionFinalization function I see the setImmediate()
function in use
async waitForTransactionFinalization(transactionHash, timeoutTime) {
assertValidHash(transactionHash);
return new Promise(async (resolve, reject) => {
const abortController = new AbortController();
if (timeoutTime) {
setTimeout(() => {
abortController.abort();
reject(new Error('Function timed out.'));
}, timeoutTime);
}
const blockStream = this.getFinalizedBlocks(abortController.signal);
const response = await this.getBlockItemStatus(transactionHash);
if (response.status === 'finalized') {
// Simply doing `abortController.abort()` causes an error.
// See: https://github.com/grpc/grpc-node/issues/1652
setImmediate(() => abortController.abort());
return resolve(response.outcome.blockHash);
}
try {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
for await (const _ of blockStream) {
const response = await this.getBlockItemStatus(transactionHash);
if (response.status === 'finalized') {
setImmediate(() => abortController.abort());
return resolve(response.outcome.blockHash);
}
}
if (!abortController.signal.aborted) {
return reject(new Error('Unexpected end of stream.'));
}
}
catch (error) {
return reject(error);
}
});
}
It seems that setImmediate()
is not cross-browser compatible as we see on developer.mozilla
https://developer.mozilla.org/pt-BR/docs/Web/API/Window/setImmediate
How can I resolve this error?
I’m using the createConcordiumClient
from lib @concordium/web-sdk
version ^3.4.0
Thanks.