Adding custom implementation of Promise.withResolvers
This commit is contained in:
parent
d0a0fcb105
commit
5abb6ce167
@ -1,5 +1,6 @@
|
||||
import tdl from 'tdl';
|
||||
import { platform } from 'node:process';
|
||||
import Utils from '../utils/utils.js';
|
||||
|
||||
class TGClient {
|
||||
|
||||
@ -91,7 +92,7 @@ class TGClient {
|
||||
}
|
||||
});
|
||||
|
||||
let sendStatusTask = Promise.withResolvers();
|
||||
let sendStatusTask = Utils.promiseWithResolvers();
|
||||
this.sendTasks.set(message.id, sendStatusTask);
|
||||
return await sendStatusTask.promise;
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { TGClient } from './tgclient.js';
|
||||
import Utils from '../utils/utils.js';
|
||||
|
||||
class TGProvider {
|
||||
|
||||
@ -45,7 +46,7 @@ class TGProvider {
|
||||
async getReport(number) {
|
||||
try {
|
||||
await this.tgClient.sendMessage(this.chat, number);
|
||||
let waitResponseTask = Promise.withResolvers();
|
||||
let waitResponseTask = Utils.promiseWithResolvers();
|
||||
this.checksMap.set(number, waitResponseTask);
|
||||
setTimeout(() => {
|
||||
waitResponseTask.reject(Error('TG report timeout'));
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"server": "node --js-promise-withresolvers --async-stack-traces --trace-warnings index.js",
|
||||
"migration": "node --js-promise-withresolvers --async-stack-traces --trace-warnings migration.js",
|
||||
"server": "node --async-stack-traces --trace-warnings index.js",
|
||||
"migration": "node --async-stack-traces --trace-warnings migration.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Selim Mustafaev",
|
||||
|
||||
@ -133,6 +133,15 @@ class Utils {
|
||||
let date = (new Date(...dateParams)).getTime();
|
||||
return Math.floor(date/1000);
|
||||
}
|
||||
|
||||
static promiseWithResolvers() {
|
||||
let resolve, reject;
|
||||
const promise = new Promise((res, rej) => {
|
||||
resolve = res;
|
||||
reject = rej;
|
||||
});
|
||||
return { promise, resolve, reject };
|
||||
}
|
||||
}
|
||||
|
||||
export default Utils;
|
||||
Loading…
Reference in New Issue
Block a user