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.

I notice that in IncomingForm.parse(), the callback function is not returned, simply run. this makes promisification impossible, as far as I know. Is there a reason why the callbacks are not returned?

Right now I would like to get a return value out of the parse(), since the callback does fit the standard node callback format (function(err, [args...])). I need to use the result of the parse in another module which I cannot modify…

If changing the code to be return cb(err, fields, files) is not a possibility, is there a way to mimic a return value?

thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
tunnckoCorecommented, Aug 22, 2017

You can’t return from callbacks which is normal. If you want you can create promise wrapper for formidable if there’s no one already.

Something like

function formidablePromise (req, opts) {
  return new Promise(function (resolve, reject) {
    var form = new formidable.IncomingForm(opts)
    form.parse(req, function (err, fields, files) {
      if (err) return reject(err)
      resolve({ fields: fields, files: files })
    })
  })
}
2reactions
GrosSacASaccommented, Nov 27, 2019

It looks resolved 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript Promisification - W3docs
Promisification is a long term for a straightforward transformation. It represents a conversion of the function, which accepts a callback into a function ......
Read more >
Promisification - Bluebird JS
Promisification means converting an existing promise-unaware API to a promise-returning API. The usual way to use promises in node is to Promise.promisifyAll ...
Read more >
How to Write Your Own Promisify Function from Scratch
Promisification means transformation. It's a conversion of a function that accepts a callback into a function returning a promise. Using Node.
Read more >
Promisification in JavaScript: How to and When is It Safe?
The best and easiest way is to use an already implemented method for turning a function that accepts a callback into a promise....
Read more >
Promise, Promisification, Promisify Function - Techfastly
Promise is definitely a good approach when it comes to async/await. Even so, it cannot completely replace callback. Promise has only one ...
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