node/test/parallel/test-async-wrap-uid.js
Andreas Madsen 4ef04c7c4c async_wrap: make uid the first argument in init
All other hooks have uid as the first argument, this makes it consistent
for all hooks.

PR-URL: https://github.com/nodejs/node/pull/4600
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2016-02-21 22:12:41 +11:00

57 lines
1,021 B
JavaScript

'use strict';
require('../common');
const fs = require('fs');
const assert = require('assert');
const async_wrap = process.binding('async_wrap');
const storage = new Map();
async_wrap.setupHooks(init, pre, post, destroy);
async_wrap.enable();
function init(uid) {
storage.set(uid, {
init: true,
pre: false,
post: false,
destroy: false
});
}
function pre(uid) {
storage.get(uid).pre = true;
}
function post(uid) {
storage.get(uid).post = true;
}
function destroy(uid) {
storage.get(uid).destroy = true;
}
fs.access(__filename, function(err) {
assert.ifError(err);
});
fs.access(__filename, function(err) {
assert.ifError(err);
});
async_wrap.disable();
process.once('exit', function() {
assert.strictEqual(storage.size, 2);
for (const item of storage) {
const uid = item[0];
const value = item[1];
assert.strictEqual(typeof uid, 'number');
assert.deepStrictEqual(value, {
init: true,
pre: true,
post: true,
destroy: true
});
}
});