Skip to content

Instantly share code, notes, and snippets.

@wentout
Created October 19, 2019 19:53
Show Gist options
  • Save wentout/ce0a1ddf2f10d1610ce541f2137befc9 to your computer and use it in GitHub Desktop.
Save wentout/ce0a1ddf2f10d1610ce541f2137befc9 to your computer and use it in GitHub Desktop.
cls-hooked test
var createNamespace = require('cls-hooked').createNamespace;
const fn = () => {
var getNamespace = require('cls-hooked').getNamespace;
var session = getNamespace('my session');
var user = session.get('user');
process._rawDebug(user);
// let testFailed = false;
// done(testFailed);
};
(() => {
const name = 'nested jump test';
const bfn = fn.bind(null);
var runStorage = [];
const intervalPointer = setInterval(() => {
runStorage.forEach((run, i) => {
process.nextTick(() => {
setTimeout(() => {
process.emit('TestJumpEvent', i);
}, 50);
});
});
// runStorage = [];
}, 100);
process.once('TestJumpEvent', (index) => {
// process._rawDebug('im here', dive.ctx, runStorage[index].toString());
runStorage[index]();
});
const eventRunner = () => {
bfn();
clearInterval(intervalPointer);
};
process.once('TestEvent', eventRunner);
const jumpDescriptor = (cb) => {
return () => {
setTimeout(() => {
setImmediate(() => {
cb();
});
}, 100);
};
};
var session = createNamespace('my session');
session.run(((cb) => {
session.set('user', 'some description');
setTimeout(() => {
runStorage.push(jumpDescriptor(cb));
}, 100);
}).bind(null, () => {
setTimeout(() => {
process.nextTick(() => {
process.emit('TestEvent');
});
}, 100);
}));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment