setTimeout
) are tasks
startTimer();
a();
setTimeout(b, 0);
c();
stopTimer();
How long does it take the following program, including `b`, to execute?
startTimer();
a();
setTimeout(b, 0); // asynchronous
c();
stopTimer();
startTimer(); // 1
a();
setTimeout(b, 0); // asynchronous
c();
stopTimer();
startTimer(); // 1
a(); // 2
setTimeout(b, 0); // asynchronous
c();
stopTimer();
startTimer(); // 1
a(); // 2
setTimeout(b, 0); // asynchronous
c(); // 3
stopTimer();
startTimer(); // 1
a(); // 2
setTimeout(b, 0); // asynchronous
c(); // 3
stopTimer(); // 4
startTimer(); // 1
a(); // 2
setTimeout(b, 0); // asynchronous // 5
c(); // 3
stopTimer(); // 4
How can we associate data with the HTTP request in the following program?
// Assume `app` is an Express instance
app.use((req, res, next) => {
// Generate a unique identifier for this request.
const requestId = generateId();
next();
});
// Assume `app` is an Express instance
app.use((req, res, next) => {
// Generate a unique identifier for this request.
const requestId = generateId();
// Attach the identifier to the request object.
req.id = requestId;
next();
});
How can we capture a full stack trace when the following program dies?
process.binding('async_wrap')
// Requires Node 0.12 or earlier.
require('zone').enable();
zone
.create(function () {
startTimer();
a();
setTimeout(b, 0);
c();
})
.setCallback(function () {
stopTimer();
});
Using StrongLoop zone which is no longer maintained and requires Node.js 0.12 or earlier.
Any questions?