Skip to content

inspector: introduce inspector/promises API - #44250

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
ErickWendel:inspector/promisified-result-session-post
Oct 13, 2022
Merged

nodejs-github-bot merged 1 commit into
nodejs:mainfrom
ErickWendel:inspector/promisified-result-session-post

Conversation

@ErickWendel

@ErickWendel ErickWendel commented Aug 16, 2022 •

Copy link
Copy Markdown
Member

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();

@nodejs-github-bot nodejs-github-bot added inspector Issues and PRs related to the V8 inspector protocol. needs-ci PRs that need a full CI run. labels Aug 16, 2022
@ErickWendel
ErickWendel force-pushed the inspector/promisified-result-session-post branch from cdfdc2c to b1947d2 Compare August 16, 2022 15:26
@MoLow

This comment was marked as resolved.

Comment thread lib/inspector.js Resolved
@ErickWendel

ErickWendel commented Aug 16, 2022 •

Copy link
Copy Markdown
Member Author

Perhaps we should expose node:inspect/promises? Just for the sake of consistency

I thought about it, but the only function that makes sense using promises is the post function. When looking at the module there’re a lot of dependencies needed to be rewritten in case we wanna expose it as /promises

@ErickWendel
ErickWendel force-pushed the inspector/promisified-result-session-post branch from c204202 to 2efebf3 Compare August 16, 2022 16:45
@ErickWendel ErickWendel self-assigned this Aug 17, 2022
Comment thread lib/inspector.js Resolved
Comment thread doc/api/inspector.md Resolved
@Trott

Trott commented Aug 18, 2022

Copy link
Copy Markdown
Member

@nodejs/inspector

@benjamingr

Copy link
Copy Markdown
Member

Overall big +1 on the idea

When looking at the module there’re a lot of dependencies needed to be rewritten in case we wanna expose it as /promises

Why? It can even live in the same file it'd just have to be exported as /promises.

I'm not sure why this should be the one and only API that works with "omit callback to get promise back" in Node.js (this specific approach was rejected for fs for example). Namely this would mean that someone forgetting to pass a callback would now stop getting an error and would get an unhandled rejection if the .post failed instead since they might be unaware of the new return value.

Comment thread doc/api/inspector.md Resolved
@ErickWendel
ErickWendel marked this pull request as draft August 22, 2022 20:42
Comment thread lib/inspector/promises.js Resolved
@ErickWendel

Copy link
Copy Markdown
Member Author

Overall big +1 on the idea

When looking at the module there’re a lot of dependencies needed to be rewritten in case we wanna expose it as /promises

Why? It can even live in the same file it'd just have to be exported as /promises.

I'm not sure why this should be the one and only API that works with "omit callback to get promise back" in Node.js (this specific approach was rejected for fs for example). Namely this would mean that someone forgetting to pass a callback would now stop getting an error and would get an unhandled rejection if the .post failed instead since they might be unaware of the new return value.

I struggled a bit but I was able to do it o/

@ErickWendel

Copy link
Copy Markdown
Member Author

I think I'll need a deep review of the docs as I'm not sure if I'm on the right path. I copied and pasted the whole API, changed the topics, and added sections for callbacks and promises APIs following the example seeing on fs

@ErickWendel
ErickWendel marked this pull request as ready for review August 22, 2022 21:15
@ErickWendel ErickWendel changed the title inspector: add promisified result for session.post when a callback is not provided inspector: introduce inspector/promises API Aug 22, 2022
Comment thread doc/api/inspector.md Resolved

@benjamingr benjamingr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress!

@ErickWendel
ErickWendel requested review from MoLow, devsnek, ljharb and ovflowd and removed request for ovflowd August 23, 2022 17:30
Comment thread lib/inspector/promises.js Resolved
Comment thread doc/api/inspector.md Resolved

@MoLow MoLow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice addition

@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 12, 2022
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@ovflowd ovflowd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adding a blocker for docs 👀 as it doesn't follow the correct standard.

Comment thread doc/api/inspector.md
It can be accessed using:

```js
```mjs

@ovflowd ovflowd Oct 13, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc-wise, this should be somewhere else, And marked with `> Stability 1 Experimental.

E.g.:

## Promises

<!-- introduced_in=v19.0.0 -->

> Stability: 1 - Experimental

<!-- source_link=lib/inspector/promises.js -->

[...] Description.

IMHO this is a doc-blocker.

@aduh95 aduh95 Oct 13, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is marked as experimental, see https://github.com/nodejs/node/pull/44250/files#diff-d6da7e100224e744520fde97ca99f743ad9eafc83d50ed92ed2b7870f0589f68R34

<!-- introduced_in=v19.0.0 --> would not be appropriate here, those are to reference the first version that included the markdown document in the docs – which is v8.0.0 for inspector.md. This PR does contain a YAML comment block that indicates when the promise API was (will be) introduced: https://github.com/nodejs/node/pull/44250/files#diff-d6da7e100224e744520fde97ca99f743ad9eafc83d50ed92ed2b7870f0589f68R37.

I disagree this is a doc blocker, also doc can always be fixed in a semver patch, while the module can only land in a semver-major.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not saying this is a PR blocker, but felt for me like a doc blocker, if you disagree that's fine, I don't want to block this PR too much 👀

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get whether i should change it or not haha. Is it ready to be landed? cc @aduh95 @ovflowd

@aduh95 aduh95 Oct 13, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we push one more commit to that branch, the PR is extremely unlikely to land on v19.x and would need to wait for 20.x, so I'd say it's probably not completely ready, but that's fine because we land it as experimental.
I'm planing on landing it as soon as we get a passing CI.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! @aduh95.

for the next PR @ovflowd I didn't get what you suggested to change. I plan to:

change connect and disconnect functions to be async (this might lead me to change something in cpp to get those events (no idea how to do it haha)) and what you suggested adding here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, @ErickWendel not sure, but I was just making suggestions to the API docs you were writing xD

But it's all fine and this landed 🎉

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@aduh95 aduh95 added the commit-queue PRs queued for automated landing through the Commit Queue. label Oct 13, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Oct 13, 2022
@nodejs-github-bot
nodejs-github-bot merged commit 0324529 into nodejs:main Oct 13, 2022
@nodejs-github-bot

ghost commented Oct 13, 2022

Copy link
Copy Markdown
Collaborator

Landed in 0324529

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. inspector Issues and PRs related to the V8 inspector protocol. needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.