Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- const common = require("../common");
- const assert = require("assert");
- const { AsyncContext } = require("async_hooks");
- const asyncContext = new AsyncContext();
- const tasks = [];
- asyncContext.enter(store => {
- store.set("hello", "world");
- tasks.push(() => {
- setTimeout(() => {
- assert.strictEqual(asyncContext.getStore().get("hello"), "world");
- }, 200);
- });
- });
- asyncContext.enter(store => {
- store.set("hello", "earth");
- tasks.push(() => {
- setTimeout(() => {
- assert.strictEqual(asyncContext.getStore().get("hello"), "earth");
- }, 200);
- });
- });
- process.once('uncaughtException', () => {
- assert.strictEqual(asyncContext.getStore().get("hello"), "uncaughtException");
- });
- asyncContext.enter(store => {
- store.set("hello", "uncaughtException");
- tasks.push(() => {
- setTimeout(() => {
- try {
- throw new Error('test');
- } catch (err) {
- process.nextTick(() => {
- throw err;
- });
- }
- }, 200);
- });
- });
- setTimeout(() => {
- asyncContext.enter(store => {
- store.set("hello", "moon");
- setTimeout(() => {
- assert.strictEqual(asyncContext.getStore().get("hello"), "moon");
- setTimeout(() => {
- tasks.forEach(task => {
- task();
- });
- }, 100);
- }, 200);
- });
- }, 100);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement