-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: add Timer/Immediate to promisifyed setTimer/setImmediate
The current implementation of the promisified setTimeout and setImmediate does not make the Timeout or Immediate available, so they cannot be canceled or unreffed. The docs and code follow the pattern established by child_process - lib/child_process.js#L150-L171 - doc/api/child_process.md#L217-L222
- Loading branch information
Caleb ツ Everett
committed
Sep 10, 2019
1 parent
f2e35ff
commit c0367dc
Showing
6 changed files
with
72 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
const { mustNotCall } = require('../common'); | ||
const { promisify } = require('util'); | ||
|
||
const setImmediateAsync = promisify(setImmediate); | ||
|
||
const expected = ['foo', 'bar', 'baz']; | ||
const promise = setImmediateAsync(...expected); | ||
promise.then(() => mustNotCall('expected immediate to be cleared')); | ||
clearImmediate(promise.immediate); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
require('../common'); | ||
const { strictEqual } = require('assert'); | ||
const { promisify } = require('util'); | ||
|
||
const setImmediateAsync = promisify(setImmediate); | ||
|
||
const expected = ['foo', 'bar', 'baz']; | ||
// N.B. the promisified version of setImmediate will resolve with the _first_ | ||
// value, not an array of all values. | ||
setImmediateAsync(...expected) | ||
.then((actual) => strictEqual(actual, expected[0])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
const { mustNotCall } = require('../common'); | ||
const { promisify } = require('util'); | ||
|
||
const setTimeoutAsync = promisify(setTimeout); | ||
|
||
const expected = ['foo', 'bar', 'baz']; | ||
const promise = setTimeoutAsync(10, ...expected); | ||
promise.then(() => mustNotCall('expected timeout to be cleared')); | ||
clearTimeout(promise.timeout); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
require('../common'); | ||
const { strictEqual } = require('assert'); | ||
const { promisify } = require('util'); | ||
|
||
const setTimeoutAsync = promisify(setTimeout); | ||
|
||
const expected = ['foo', 'bar', 'baz']; | ||
// N.B. the promisified version of setTimeout will resolve with the _first_ | ||
// value, not an array of all values. | ||
setTimeoutAsync(10, ...expected) | ||
.then((actual) => strictEqual(actual, expected[0])); |