question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replace callback-based API with promise-based async functions

See original GitHub issue

Replace 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:closed
  • Created 2 years ago
  • Comments:37

github_iconTop GitHub Comments

1reaction
kibertoadcommented, Aug 31, 2021

@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?

1reaction
rudolfbykercommented, Aug 31, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found