summaryrefslogtreecommitdiff
path: root/test/parallel/test-async-hooks-promise.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2017-06-04 13:35:56 +0200
committerAnna Henningsen <anna@addaleax.net>2017-06-08 23:59:58 +0200
commit8f39881b743d65a0be8bd4ab0b4574f7109bcd07 (patch)
treec328ff2b7fa36c46cdbcbafdf8325b6a4c1b0381 /test/parallel/test-async-hooks-promise.js
parent02aea0690deaa1a79fe8f5c7c8b8119a45347a4d (diff)
downloadandroid-node-v8-8f39881b743d65a0be8bd4ab0b4574f7109bcd07.tar.gz
android-node-v8-8f39881b743d65a0be8bd4ab0b4574f7109bcd07.tar.bz2
android-node-v8-8f39881b743d65a0be8bd4ab0b4574f7109bcd07.zip
async_hooks: use resource objects for Promises
Use `PromiseWrap` resource objects whose lifetimes are tied to the `Promise` instances themselves to track promises, and have a `.promise` getter that points to the `Promise` and a `.parent` property that points to the parent Promise’s resource object, if there is any. The properties are implemented as getters for internal fields rather than normal properties in the hope that it helps keep performance for the common case that async_hooks users will often not inspect them. PR-URL: https://github.com/nodejs/node/pull/13452 Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'test/parallel/test-async-hooks-promise.js')
-rw-r--r--test/parallel/test-async-hooks-promise.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/parallel/test-async-hooks-promise.js b/test/parallel/test-async-hooks-promise.js
new file mode 100644
index 0000000000..ea5e59d319
--- /dev/null
+++ b/test/parallel/test-async-hooks-promise.js
@@ -0,0 +1,23 @@
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const async_hooks = require('async_hooks');
+
+const initCalls = [];
+
+async_hooks.createHook({
+ init: common.mustCall((id, type, triggerId, resource) => {
+ assert.strictEqual(type, 'PROMISE');
+ initCalls.push({id, triggerId, resource});
+ }, 2)
+}).enable();
+
+const a = Promise.resolve(42);
+const b = a.then(common.mustCall());
+
+assert.strictEqual(initCalls[0].triggerId, 1);
+assert.strictEqual(initCalls[0].resource.parentId, undefined);
+assert.strictEqual(initCalls[0].resource.promise, a);
+assert.strictEqual(initCalls[1].triggerId, initCalls[0].id);
+assert.strictEqual(initCalls[1].resource.parentId, initCalls[0].id);
+assert.strictEqual(initCalls[1].resource.promise, b);