Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: attach return value to promisified functions #28529

Closed
wants to merge 1 commit into from
Closed

util: attach return value to promisified functions #28529

wants to merge 1 commit into from

Conversation

Hakerh400
Copy link
Contributor

@Hakerh400 Hakerh400 commented Jul 4, 2019

Some functions that perform asynchronous tasks and
take a callback also return a synchronous result which
can be used in the same tick. Previously util.promisify
was discarding the return value.

While #28325 solved the problem for some specific functions, the general problem for user-defined functions remained. It seems that not so rare practice is to return a useful value along with scheduling asynchronous actions in a function which takes a callback.

Documentation is not added yet. I would like to hear some feedback first regarding whether this change is a good change (or maybe some better suggestions for the symbol name?).

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Some functions that perform asynchronous tasks and
take a callback also return a synchronous result which
can be used in the same tick. Previously util.promisify
was discarding the return value.
@nodejs-github-bot nodejs-github-bot added the util Issues and PRs related to the built-in util module. label Jul 4, 2019
@devsnek
Copy link
Member

devsnek commented Jul 4, 2019

this seems best left to the specific function. we probably want to avoid weird new patterns in the ecosystem like checking promises for node symbols.

@BridgeAR
Copy link
Member

BridgeAR commented Jul 4, 2019

I think a good alternative to adding this is to document how to use a custom promisify function that does exactly this? If we go for something like this, a better name might be: syncValue, syncReturn, returnValue or something like that?

@BridgeAR
Copy link
Member

BridgeAR commented Jul 4, 2019

@nodejs/promises-debugging @nodejs/util PTAL

@Hakerh400 Hakerh400 closed this Jul 4, 2019
@benjamingr
Copy link
Member

This is not really idiomatic and it makes more sense to decorate the promise value and not the function return value.

I'm not in favour of this landing.

It is an interesting idea though - would love to see more :]

@Hakerh400 Hakerh400 deleted the prom branch July 25, 2019 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants