inspector: introduce inspector/promises API
This PR introduces the new inspector/promises
API with the session.post
function.
Before with Callbacks API:
const { Session } = require('inspector');
const session = new Session();
session.connect();
session.post('Profiler.enable', () => {
session.post('Profiler.start', () => {
session.post('Profiler.stop', (err, { profile }) => {
fs.writeFileSync('./profile.cpuprofile', JSON.stringify(profile));
session.disconnect();
});
});
});
After with Promises:
const { Session } = require('inspector/promises');
const session = new Session();
session.connect();
await session.post('Profiler.enable');
await session.post('Profiler.start');
const { profile } = await session.post('Profiler.stop')
fs.writeFileSync('./profile.cpuprofile', JSON.stringify(profile));
session.disconnect();