Skip to content

Commit 09fd6c3

Browse files
committed
[Refactor] use async-function for the eval parts
Hopefully fixes #31.
1 parent db36da5 commit 09fd6c3

File tree

5 files changed

+8
-27
lines changed

5 files changed

+8
-27
lines changed

getAsyncFunc.d.ts

-5
This file was deleted.

getAsyncFunc.js

-10
This file was deleted.

index.d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import type { AsyncFunction } from 'async-function';
2+
13
declare namespace isAsyncFunction {
2-
type AsyncFunction = (...args: any[]) => Promise<any>
4+
export type { AsyncFunction };
35
}
46

5-
declare function isAsyncFunction(fn: unknown): fn is isAsyncFunction.AsyncFunction;
7+
declare function isAsyncFunction(fn: unknown): fn is AsyncFunction;
68

79
export = isAsyncFunction;

index.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ var isFnRegex = safeRegexTest(/^\s*async(?:\s+function(?:\s+|\()|\s*\()/);
1010
var hasToStringTag = require('has-tostringtag/shams')();
1111
var getProto = require('get-proto');
1212

13-
var getAsyncFunc = require('./getAsyncFunc');
14-
15-
/** @type {import('.').AsyncFunction | false} */
16-
var AsyncFunction;
13+
var getAsyncFunc = require('async-function');
1714

1815
/** @type {import('.')} */
1916
module.exports = function isAsyncFunction(fn) {
@@ -30,10 +27,6 @@ module.exports = function isAsyncFunction(fn) {
3027
if (!getProto) {
3128
return false;
3229
}
33-
if (typeof AsyncFunction === 'undefined') {
34-
var asyncFunc = getAsyncFunc();
35-
// eslint-disable-next-line no-extra-parens
36-
AsyncFunction = asyncFunc ? /** @type {import('.').AsyncFunction} */ (getProto(asyncFunc)) : false;
37-
}
38-
return AsyncFunction && getProto(fn) === AsyncFunction;
30+
var asyncFunc = getAsyncFunc();
31+
return asyncFunc && asyncFunc.prototype === getProto(fn);
3932
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"url": "https://github.com/inspect-js/is-async-function/issues"
4646
},
4747
"dependencies": {
48+
"async-function": "^1.0.0",
4849
"call-bound": "^1.0.3",
4950
"get-proto": "^1.0.1",
5051
"has-tostringtag": "^1.0.2",

0 commit comments

Comments
 (0)