1'use strict'; 2 3const common = require('../common'); 4 5const { 6 PerformanceObserver, 7 performance: { 8 timerify, 9 }, 10} = require('perf_hooks'); 11 12const assert = require('assert'); 13 14const { 15 setTimeout: sleep 16} = require('timers/promises'); 17 18let check = false; 19 20async function doIt() { 21 await sleep(100); 22 check = true; 23 return check; 24} 25 26const obs = new PerformanceObserver(common.mustCall((list) => { 27 const entry = list.getEntries()[0]; 28 assert.strictEqual(entry.name, 'doIt'); 29 assert(check); 30 obs.disconnect(); 31})); 32 33obs.observe({ type: 'function' }); 34 35const timerified = timerify(doIt); 36 37const res = timerified(); 38assert(res instanceof Promise); 39res.then(common.mustCall(assert)); 40