Replace callback-based API with promise-based async functions
See original GitHub issueReplace Request with superagent (which is faster: https://github.com/fdesjardins/node-http-client-bench) or axios (which is more popular) for promise support.
Undici is an even faster option (x2-x3 speed-up), but since it does not rely on http
module, it would break nock-based mocks if users had any, which makes me hesitant.
Issue Analytics
- State:
- Created 2 years ago
- Comments:37
Top Results From Across the Web
Replacing Callbacks with Promises - Async JavaScript [Book]
The most straightforward way to use Promises with a callback-based API is to create a Deferred and pass its trigger function(s) as the...
Read more >How do I convert an existing callback API to promises?
I'm wanting to wrap all my synchronous Noje.js functions in a Promise so as to remove all synchronous code from my Node app,...
Read more >Converting Callbacks to Promises in Node.js - Stack Abuse
Asynchronous JavaScript heavily used callbacks, but now use Promises as it's easier to manage. In this article, we'll convert callbacks to ...
Read more >Converting callbacks to promises | Zell Liew
It's easier to work with Promises and Async/await compared to callbacks. I teach you how to convert any callback into a promise.
Read more >Using Callbacks With Async/Await - Maxim Orlov
I'll teach you how to change a function's signature, even when you don't have control over its implementation. Transforming callback-based asynchronous ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@rudolfbyker I don’t think you strictly need to use either, original implementation just takes a plain simple Request call and wraps a Duplex (which writes to request and reads from response) around it. Now if you would use
undici.pipeline
, it should do all that job for you,Dispatcher.pipeline
should create exactly the kind of Duplexer that we create ourselves now. I would recommend against refactoring this part right now, though. There are no tests, so difficult to say if we break something in a major way. I suggest doing bare minimum change (replace simple Request call with simple callback-based Undici call) for now, and later on I will write a test and attempt a proper refactoring. Does that work for you?I’m not concerned with breaking changes. We are moving towards the first major release, so I think we should be relentless. If we had a big software house backing the project, that would be a different story.
I’ll check out undici and get back to you. I need to get this done today.