Support promises in async version
See original GitHub issueIssue Description
Hey! Great library!
I am using it in the browser, and it would be great if the async versions would support promises as well instead of just callbacks.
Ideally it would look something like this:
const buffer = await fflate.zip(
{
'index.html': fflate.strToU8(str),
// other files...
},
{ level: 4 }
);
It looks like synchronous code but it doesn’t block the main thread.
It makes sense to support promises, newer versions of node are doing so with stuff like fs/promises
and timers/promises
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to use promises - Learn web development | MDN
Promises are the foundation of asynchronous programming in modern JavaScript. A promise is an object returned by an asynchronous function, ...
Read more >Understanding the Event Loop, Callbacks, Promises, and ...
A promise represents the completion of an asynchronous function. It is an object that might return a value in the future. It accomplishes...
Read more >Async functions: making promises friendly - web.dev
Async functions allow you to write promise-based code as if it were synchronous.
Read more >25. Promises for asynchronous programming - Exploring JS
Promises are an alternative to callbacks for delivering the results of an asynchronous computation. They require more effort from implementors of asynchronous ...
Read more >Promises, async/await - The Modern JavaScript Tutorial
Promises, async/await · Introduction: callbacks · Promise · Promises chaining · Error handling with promises · Promise API · Promisification · Microtasks ·...
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 Free
Top 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
I have thought of using a separate build for IE11. I write ESNext for all of my personal projects and make heavy use of
Promise
; usually I don’t try to support IE11 as it’s a dead browser, but when I do I use the polyfill you linked forPromise
. The problem for a project like this is that the entire package is designed to be lower-level and to support ancient engines, so adding one component of new JS is incongruous. Check out #75, in whichfflate
needed to support another rare engine, V4: if there’s a special bug withPromise
in V4, as there was for typed arrays, I’d have to commit to supporting it. I’ve also been asked to add support for WHATWG streams in the streaming APIs, but those are even more recent and even more unsupported thanPromise
. Basically, the fewer modern featuresfflate
uses, the more maintainable it is for me and the more compatible it is for every user.As support for features of new JS is such a popular feature request, I’ll create a wrapper for
fflate
that supports the modern features you want. See #80 for more info.Future users can just search the issues tab for “Promise” and they’ll find it. Thanks for the feature request!