Skip to content

Commit 7125543

Browse files
authored
fix async functions (#22)
1 parent 196a100 commit 7125543

File tree

7 files changed

+808
-503
lines changed

7 files changed

+808
-503
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- '**'
1212

1313
env:
14-
PRIMARY_NODE_VERSION: 16.x
14+
PRIMARY_NODE_VERSION: 18.x
1515
PRIMARY_OS: ubuntu-latest
1616
REGISTRY: https://registry.npmjs.org/
1717

@@ -22,7 +22,7 @@ jobs:
2222
strategy:
2323
matrix:
2424
os: [ ubuntu-latest ]
25-
node-version: [ 6.x, 8.x, 10.x, 12.x, 14.x, 16.x, 18.x ]
25+
node-version: [ 14.x, 16.x, 18.x ]
2626

2727
steps:
2828

@@ -87,7 +87,7 @@ jobs:
8787
strategy:
8888
matrix:
8989
os: [ ubuntu-latest ]
90-
node-version: [ 6.x ]
90+
node-version: [ 18.x ]
9191
needs: [ test ]
9292
if: github.event_name == 'release' && github.event.action == 'published'
9393
steps:

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44
## Development
55
- nothing yet
66

7+
## [v4.0.0](https://github.com/regevbr/busywait.js/compare/v3.1.3...v4.0.0)
8+
### BREAKING CHANGES
9+
- Dropped support for node versions below 14
10+
### Fixed
11+
- functions with `async` modifier were not recognized as functions
12+
13+
714
## [v3.1.3](https://github.com/regevbr/busywait.js/compare/v3.1.2...v3.1.3)
815
### Fixed
916
- Support for node 18

package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "busywait",
3-
"version": "3.1.3",
3+
"version": "4.0.0",
44
"description": "Async busy wait",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -38,7 +38,7 @@
3838
"backoff-strategy"
3939
],
4040
"engines": {
41-
"node": "^6 || ^8 || ^10 || ^12 || ^14 || ^16 || ^18"
41+
"node": "^14 || ^16 || ^18"
4242
},
4343
"files": [
4444
"/dist/*.d.ts",
@@ -52,23 +52,23 @@
5252
"homepage": "https://github.com/regevbr/busywait.js#readme",
5353
"dependencies": {},
5454
"devDependencies": {
55-
"@istanbuljs/nyc-config-typescript": "0.1.3",
56-
"@types/chai": "^4.2.17",
57-
"@types/chai-as-promised": "^7.1.3",
58-
"@types/mocha": "^8.2.2",
59-
"@types/node": "^15.0.1",
60-
"chai": "^4.3.4",
55+
"@istanbuljs/nyc-config-typescript": "^1.0.2",
56+
"@types/chai": "^4.3.4",
57+
"@types/chai-as-promised": "^7.1.5",
58+
"@types/mocha": "^10.0.1",
59+
"@types/node": "^18.11.15",
60+
"chai": "^4.3.7",
6161
"chai-as-promised": "^7.1.1",
62-
"coveralls": "^3.1.0",
62+
"coveralls": "^3.1.1",
6363
"dirty-chai": "^2.0.1",
6464
"mocha": "^6.2.3",
65-
"nyc": "14.1.1",
66-
"source-map-support": "^0.5.19",
65+
"nyc": "^15.1.0",
66+
"source-map-support": "^0.5.21",
6767
"mocha-param": "^2.0.1",
68-
"sinon": "^7.3.2",
69-
"sinon-chai": "^3.6.0",
70-
"ts-node": "^8.10.2",
68+
"sinon": "^15.0.0",
69+
"sinon-chai": "^3.7.0",
70+
"ts-node": "^10.9.1",
7171
"tslint": "^6.1.3",
72-
"typescript": "^4.8.4"
72+
"typescript": "^4.9.4"
7373
}
7474
}

src/index.ts

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,3 @@
1-
/* istanbul ignore next */
2-
// @ts-ignore
3-
// tslint:disable-next-line:variable-name
4-
const __awaiter = (thisArg, _arguments, P, generator) => {
5-
function adopt(value: any) {
6-
return value instanceof P ? value : new P((resolve: any) => {
7-
resolve(value);
8-
});
9-
}
10-
11-
return new (P || (P = Promise))((resolve: any, reject: any) => {
12-
function fulfilled(value: any) {
13-
try {
14-
step(generator.next(value));
15-
} catch (e) {
16-
reject(e);
17-
}
18-
}
19-
20-
function rejected(value: any) {
21-
try {
22-
step(generator.throw(value));
23-
} catch (e) {
24-
reject(e);
25-
}
26-
}
27-
28-
function step(result: any) {
29-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
30-
}
31-
32-
step((generator = generator.apply(thisArg, _arguments || [])).next());
33-
});
34-
};
35-
361
type _CheckFn<T> = (iteration: number, delay: number, totalDelay: number) => T;
372
export type SyncCheckFn<T> = T extends Promise<any> ? never : _CheckFn<T>;
383
export type ASyncCheckFn<T> = _CheckFn<Promise<T>>;
@@ -62,7 +27,10 @@ type Resolve<T> = (result: T) => void;
6227
type Reject = (error: Error) => void;
6328
type Delayer = (iteration: number) => number;
6429

65-
const isFunction = (value: any): value is () => any => toString.call(value) === '[object Function]';
30+
const isFunction = (value: any): value is () => any => {
31+
const str = Object.prototype.toString.call(value);
32+
return str === '[object Function]' || str === '[object AsyncFunction]';
33+
}
6634

6735
const isNumber = (value: any): value is number => typeof value === 'number';
6836

src/test/src/index.spec.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface IParam {
1010

1111
type Done = (error?: any) => void;
1212

13-
describe('busywait.js', function() {
13+
describe('busywait.js', function () {
1414

1515
this.timeout(10000);
1616

@@ -85,9 +85,21 @@ describe('busywait.js', function() {
8585
});
8686
};
8787

88+
const nativeAsyncCheck = async (iteration: number, delay: number, totalDelay: number): Promise<string> => {
89+
iterationsArray.push(iteration);
90+
delaysArray.push(delay);
91+
totalDelaysArray.push(totalDelay);
92+
if (Date.now() > waitUntil) {
93+
return successMessage;
94+
} else {
95+
throw new Error();
96+
}
97+
};
98+
8899
const params: IParam[] = [
89100
{checkFn: syncCheck},
90101
{checkFn: asyncCheck},
102+
{checkFn: nativeAsyncCheck},
91103
];
92104

93105
itParam('should complete', params, (param: IParam) => {

tsconfig.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es2016",
3+
"target": "ES2020",
44
"module": "commonjs",
55
"moduleResolution": "node",
66
"declaration": true,
@@ -17,13 +17,12 @@
1717
"strictFunctionTypes": true,
1818
"alwaysStrict": true,
1919
"noImplicitUseStrict": false,
20-
"preserveSymlinks": true,
20+
"preserveSymlinks": false,
2121
"noEmitHelpers": true,
2222
"rootDir": "src",
2323
"sourceMap": true,
2424
"lib": [
25-
"es6",
26-
"dom"
25+
"ES2020"
2726
]
2827
},
2928
"include": [

0 commit comments

Comments
 (0)