87 key: BlobKey,
88 data: Buffer | string,
89) {
90 return new Promise(async (resolve, reject) => { 91 const stream = store.createWriteStream(key, (error, metadata) => { 92 if (error) { 93 reject(error); 94 } else { 95 resolve(metadata); 96 } 97 }); 98 stream.write(data); 99 stream.end();100 });101}
102
103/** Encode utf8 string with Base58. */
144
145 it("should get block number stream", async function () {
146 const current = await client.blockchain.getCurrentBlockNum();
147 await new Promise(async (resolve, reject) => {148 const stream = client.blockchain.getBlockNumberStream();149 stream.on("data", (num) => {150 assert(num >= current);151 resolve();152 });153 stream.on("error", reject);154 });155 });
156
157 it("should get current block header", async function () {
Using promises is forbidden in places where the TypeScript compiler allows them but they are not handled properly. These situations can often arise due to a missing await keyword or just a misunderstanding of the way async functions are handled/awaited.
const promise = Promise.resolve('value');
if (promise) {
// Do something
}
const val = promise ? 123 : 456;
while (promise) {
// Do something
}
const promise = Promise.resolve('value');
if (await promise) {
// Do something
}
const val = (await promise) ? 123 : 456;
while (await promise) {
// Do something
}
for (const value of [1, 2, 3]) {
await doSomething(value);
}
new Promise((resolve, reject) => {
// Do something
resolve();
});
const eventEmitter = new EventEmitter();
eventEmitter.on('some-event', () => {
doSomething();
});