Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

util.callbackify for async functions #109

Closed
benjamingr opened this issue Apr 23, 2017 · 12 comments · Fixed by nodejs/node#12712
Closed

util.callbackify for async functions #109

benjamingr opened this issue Apr 23, 2017 · 12 comments · Fixed by nodejs/node#12712

Comments

@benjamingr
Copy link
Member

benjamingr commented Apr 23, 2017

Hey,

From nodejs/promises#6 originally, but seeing that util.promisify is finally in sight, I think this might be worth proposing too.

I propose that for compatibility reasons, and so that callback users using Node can keep working with their tooling to add a util.callbackify function that converts an async function to a callback taking function.

For example:

async function foo() {
  let data1 = await promiseApi(..);
  let data2 = await promiseApiOther(data1);
  return result;
}
const foo2 = util.callbackify(foo);
foo2(function(err, data) {
  // error here if foo threw
  // use data here
});

This is likely faster in core, and would enable seamless integration of async functions into callback APIs and code bases. Seeing as we're not going to make a promisified core any time soon - this is beneficial for interoping between code bases using callbacks and async functions together.

How do @nodejs/collaborators feel about this?

@mcollina
Copy link
Member

I think we need this if we want to ship promisify.

@Qard
Copy link
Member

Qard commented Apr 23, 2017

👍 from me. Regardless of how core feels about promises and async/await, userland will use them, so we need to ensure interop works well.

@cjihrig
Copy link

cjihrig commented Apr 24, 2017

I think it makes sense if promisify makes it in.

@vkurchatkin
Copy link

-1 unless we have something to offer in terms of performance

@bnoordhuis
Copy link
Member

Someone has to say it: s/toCallback/callbackify/

@evanlucas
Copy link

Someone has to say it: s/toCallback/callbackify/

Yea, can we be consistent?

@benjamingr benjamingr changed the title util.toCallback for async functions util.callbackify for async functions Apr 24, 2017
@benjamingr
Copy link
Member Author

@bnoordhuis @evanlucas this issue was mostly to see if there is interest - I've amended to callbackify.

@refack
Copy link

refack commented Apr 26, 2017

At the moment I see 20 👍 so
😀me
imagegauntlet
🏋️‍Picking up

(ouch! my back 😖)

@refack
Copy link

refack commented Apr 28, 2017

@not-an-aardvark I'm working on a PR, finishing some tests and will upload tomorrow for you'll to review...

@eljefedelrodeodeljefe
Copy link

I'd be happy if we could push nodejs/node#12712 forward.

refack added a commit to refack/node that referenced this issue Jun 7, 2017
Add `util.callbackify(function)` for creating callback style functions
from functions returning a `Promise`/`awaitable`

Fixes: nodejs/CTC#109
@refack
Copy link

refack commented Jun 11, 2017

I believe this could be closed now that nodejs/node@af3aa68 landed

@benjamingr
Copy link
Member Author

Sweet! Thanks a lot @refack :)

refack added a commit to refack/node that referenced this issue Jun 17, 2017
Add `util.callbackify(function)` for creating callback style functions
from functions returning a `Thenable`

PR-URL: nodejs#12712
Fixes: nodejs/CTC#109
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Teddy Katz <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
addaleax pushed a commit to nodejs/node that referenced this issue Jun 20, 2017
Add `util.callbackify(function)` for creating callback style functions
from functions returning a `Thenable`

Original-PR-URL: #12712
Fixes: nodejs/CTC#109
Original-Reviewed-By: Benjamin Gruenbaum <[email protected]>
Original-Reviewed-By: Teddy Katz <[email protected]>
Original-Reviewed-By: Matteo Collina <[email protected]>
Original-Reviewed-By: Colin Ihrig <[email protected]>
Original-Reviewed-By: Timothy Gu <[email protected]>
Original-Reviewed-By: Anna Henningsen <[email protected]>

PR-URL: #13750
Reviewed-By: Anna Henningsen <[email protected]>
addaleax pushed a commit to nodejs/node that referenced this issue Jun 21, 2017
Add `util.callbackify(function)` for creating callback style functions
from functions returning a `Thenable`

Original-PR-URL: #12712
Fixes: nodejs/CTC#109
Original-Reviewed-By: Benjamin Gruenbaum <[email protected]>
Original-Reviewed-By: Teddy Katz <[email protected]>
Original-Reviewed-By: Matteo Collina <[email protected]>
Original-Reviewed-By: Colin Ihrig <[email protected]>
Original-Reviewed-By: Timothy Gu <[email protected]>
Original-Reviewed-By: Anna Henningsen <[email protected]>

PR-URL: #13750
Reviewed-By: Anna Henningsen <[email protected]>
addaleax pushed a commit to nodejs/node that referenced this issue Jun 24, 2017
Add `util.callbackify(function)` for creating callback style functions
from functions returning a `Thenable`

Original-PR-URL: #12712
Fixes: nodejs/CTC#109
Original-Reviewed-By: Benjamin Gruenbaum <[email protected]>
Original-Reviewed-By: Teddy Katz <[email protected]>
Original-Reviewed-By: Matteo Collina <[email protected]>
Original-Reviewed-By: Colin Ihrig <[email protected]>
Original-Reviewed-By: Timothy Gu <[email protected]>
Original-Reviewed-By: Anna Henningsen <[email protected]>

PR-URL: #13750
Reviewed-By: Anna Henningsen <[email protected]>
rvagg pushed a commit to nodejs/node that referenced this issue Jun 29, 2017
Add `util.callbackify(function)` for creating callback style functions
from functions returning a `Thenable`

Original-PR-URL: #12712
Fixes: nodejs/CTC#109
Original-Reviewed-By: Benjamin Gruenbaum <[email protected]>
Original-Reviewed-By: Teddy Katz <[email protected]>
Original-Reviewed-By: Matteo Collina <[email protected]>
Original-Reviewed-By: Colin Ihrig <[email protected]>
Original-Reviewed-By: Timothy Gu <[email protected]>
Original-Reviewed-By: Anna Henningsen <[email protected]>

PR-URL: #13750
Reviewed-By: Anna Henningsen <[email protected]>
addaleax pushed a commit to nodejs/node that referenced this issue Jul 11, 2017
Add `util.callbackify(function)` for creating callback style functions
from functions returning a `Thenable`

Original-PR-URL: #12712
Fixes: nodejs/CTC#109
Original-Reviewed-By: Benjamin Gruenbaum <[email protected]>
Original-Reviewed-By: Teddy Katz <[email protected]>
Original-Reviewed-By: Matteo Collina <[email protected]>
Original-Reviewed-By: Colin Ihrig <[email protected]>
Original-Reviewed-By: Timothy Gu <[email protected]>
Original-Reviewed-By: Anna Henningsen <[email protected]>

PR-URL: #13750
Reviewed-By: Anna Henningsen <[email protected]>
addaleax pushed a commit to nodejs/node that referenced this issue Jul 18, 2017
Add `util.callbackify(function)` for creating callback style functions
from functions returning a `Thenable`

Original-PR-URL: #12712
Fixes: nodejs/CTC#109
Original-Reviewed-By: Benjamin Gruenbaum <[email protected]>
Original-Reviewed-By: Teddy Katz <[email protected]>
Original-Reviewed-By: Matteo Collina <[email protected]>
Original-Reviewed-By: Colin Ihrig <[email protected]>
Original-Reviewed-By: Timothy Gu <[email protected]>
Original-Reviewed-By: Anna Henningsen <[email protected]>

PR-URL: #13750
Reviewed-By: Anna Henningsen <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants