-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
async_wrap: allow some hooks to be optional
Only enforce that the init callback is passed to setupHooks(). The remaining hooks can be optionally passed. Throw if async_wrap.enable() runs before setting the init callback or if setupHooks() is called while async wrap is enabled. Add test to verify calls throw appropriately. PR-URL: #3461 Reviewed-By: Fedor Indutny <[email protected]>
- Loading branch information
1 parent
ae46a23
commit e6b5119
Showing
2 changed files
with
35 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const async_wrap = process.binding('async_wrap'); | ||
|
||
|
||
assert.throws(function() { | ||
async_wrap.setupHooks(null); | ||
}, /init callback must be a function/); | ||
|
||
assert.throws(function() { | ||
async_wrap.enable(); | ||
}, /init callback is not assigned to a function/); | ||
|
||
// Should not throw | ||
async_wrap.setupHooks(() => {}); | ||
async_wrap.enable(); | ||
|
||
assert.throws(function() { | ||
async_wrap.setupHooks(() => {}); | ||
}, /hooks should not be set while also enabled/); |