Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
perf_hooks: make PerformanceObserver an AsyncResource
  • Loading branch information
jasnell committed Feb 26, 2018
commit 02adcf7fd283ec3dd029a1dbfc91b330bdb246b6
6 changes: 4 additions & 2 deletions lib/perf_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const {
NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END
} = constants;

const { AsyncResource } = require('async_hooks');
const L = require('internal/linkedlist');
const kInspect = require('internal/util').customInspectSymbol;
const { inherits } = require('util');
Expand Down Expand Up @@ -317,12 +318,13 @@ class PerformanceObserverEntryList {
}
}

class PerformanceObserver {
class PerformanceObserver extends AsyncResource {
constructor(callback) {
if (typeof callback !== 'function') {
const errors = lazyErrors();
throw new errors.TypeError('ERR_INVALID_CALLBACK');
}
super('PerformanceObserver');
Object.defineProperties(this, {
[kTypes]: {
enumerable: false,
Expand Down Expand Up @@ -568,7 +570,7 @@ function getObserversList(type) {

function doNotify() {
this[kQueued] = false;
this[kCallback](this[kBuffer], this);
this.runInAsyncScope(this[kCallback], this, this[kBuffer], this);
this[kBuffer][kEntries] = [];
L.init(this[kBuffer][kEntries]);
}
Expand Down