feat: add async function

This commit is contained in:
2023-08-23 11:47:50 +03:00
parent 6da7720c67
commit 79a93ef971
12 changed files with 240 additions and 124 deletions

View File

@@ -14,6 +14,7 @@ interface FunctionConstructor extends Function {
(...args: string[]): (...args: any[]) => any;
new (...args: string[]): (...args: any[]) => any;
prototype: Function;
async<ArgsT extends any[], RetT>(func: (await: <T>(val: T) => Awaited<T>, args: ArgsT) => RetT): Promise<RetT>;
}
interface CallableFunction extends Function {
@@ -75,4 +76,10 @@ setProps(Function.prototype, {
toString() {
return 'function (...) { ... }';
},
});
});
setProps(Function, {
async(func) {
if (typeof func !== 'function') throw new TypeError('Expected func to be function.');
return internals.makeAsync(func);
}
})