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.

Support a promise paradigm

See original GitHub issue

Before

    yauzl.open('file.zip', (err, zipfile) => {
      if (err) throw err
      zipfile.on('entry', (entry) => {
        zipfile.openReadStream(entry, (err, readStream) => {
          if (err) throw err
          readStream.pipe(somewhere)
        })
      })
    })

After

    const zipfile = await yauzl.open('file.zip')
    zipfile.on('entry', async (entry) => {
      const readStream = zipfile.openReadStream(entry)
        readStream.pipe(somewhere)
      })
    })

If yauzl.open and zipfile.openReadStream return Promises if no callbacks are provided, it would simplify code for people who choose to use async/await. We could remove all if (err) throw err because unhandled errors would be thrown automatically. And we don’t have as deep nesting of the code, which makes things hard to read unless functions are extracted which may otherwise not have needed to be extracted.

Of course, if callbacks are provided then no Promise is returned and code behaves as it currently does, making this change backwards-compatible.

Node v7, which will be released soon, will make native async/await available behind flags. And Node v8 will make them available without any flags. This feature would give the option to write simpler code for anyone using those versions of Node, or any version of Node with Babel (as I’m currently doing it).

Issue Analytics

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

github_iconTop GitHub Comments

8reactions
overlookmotelcommented, Apr 12, 2018

I have published an npm module yauzl-promise which promisifies the API.

Hope it’s useful to someone.

3reactions
martinkadlec0commented, Nov 14, 2016

Yes, I think wanting a Promise support just to get the Promises itself is completely valid.

Read more comments on GitHub >

github_iconTop Results From Across the Web

3. The Promise Paradigm - Mastering JavaScript ... - O'Reilly
In this chapter, we will focus on what the promises paradigm is, from where it originated, how languages implement it, and what problems...
Read more >
Promise - JavaScript - MDN Web Docs
Promise (). Creates a new Promise object. The constructor is primarily used to wrap functions that do not already support promises.
Read more >
Futures and promises - Wikipedia
In computer science, future, promise, delay, and deferred refer to constructs used for synchronizing program execution in some concurrent programming ...
Read more >
The Promise Paradigm | Mastering JavaScript Promises
In this chapter, we will focus on what the promises paradigm is, from where it originated, how languages implement it, and what problems...
Read more >
Home ⋆ Paradigm C.A.R.E.S. ⋆ Paradigm, Inc.
Learn more about our services and the jobs available with Paradigm, Inc. ... We promise to help you move forward, embarking on a...
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