| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f27a254 commit e2a801a
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,26 @@ | |||
| 1 | + // Test async-hooks fired on right | ||
| 2 | + // asyncIds & triggerAsyncId for async-await | ||
| 3 | + 'use strict'; | ||
| 4 | + | ||
| 5 | + require('../common'); | ||
| 6 | + const async_hooks = require('async_hooks'); | ||
| 7 | + const assert = require('assert'); | ||
| 8 | + | ||
| 9 | + const asyncIds = []; | ||
| 10 | + async_hooks.createHook({ | ||
| 11 | + init: (asyncId, type, triggerAsyncId) => { | ||
| 12 | + asyncIds.push([triggerAsyncId, asyncId]); | ||
| 13 | + } | ||
| 14 | + }).enable(); | ||
| 15 | + | ||
| 16 | + async function main() { | ||
| 17 | + await null; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + main().then(() => { | ||
| 21 | + // Verify the relationships between async ids | ||
| 22 | + // 1 => 2, 2 => 3 etc | ||
| 23 | + assert.strictEqual(asyncIds[0][1], asyncIds[1][0]); | ||
| 24 | + assert.strictEqual(asyncIds[0][1], asyncIds[3][0]); | ||
| 25 | + assert.strictEqual(asyncIds[1][1], asyncIds[2][0]); | ||
| 26 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments