Comments (6)
The linked commit added allOk
, allOk2
...allOk6
, and allOkArray
, and these functions are now in npm as part of [email protected]. Thanks again for requesting them.
I've linked them from the docs at the bottom of the error handling section.
One side effect is that all the allOk*
functions have bloated the compressed size of compiled reason-promise from about 1K to nearly 4K. However, I think I can eliminate most of that in a future release by taking advantage of the fact that tuples are arrays, and simply unsafely defining all the allOk*
functions as allOkArray
, which is already the case for the plain all*
functions and allArray
.
from promise.
Also, the implementation is slightly tricky for the sake of memory safety, see this comment if interested :)
Lines 279 to 289 in ae44bad
from promise.
Yes, we should add this. Thanks for the issue!
Would you like to give it a try? Otherwise, I will do it in some days. I'm on a semi-vacation ATM. Still working, but slower than normal :)
from promise.
Hey, thank you so much for this! Out of curiosity, could it have been implemented with something like this? (in ambiguous terms)
race(all(promises |> map(then(result => <if result is error then reject here using rejecter, return result>))), rejecter)
from promise.
Not with memory safety. In that pseudocode, the function that is directly called on each promise is then
. So if promises
is [p1, p2]
, the code will attach a callback to p1
and the same callback to p2
. If p1
resolves with Error(_)
, the "final" promise of allOk
gets resolved with Error(_)
, but there is no way to eagerly remove the callback on p2
— it can only be removed when p2
also resolves. So that would be a memory leak. The pseudocode might work if promises had some kind of intelligent transitive callback removal scheme, so that fast-fail in race triggered callback removal for everything passed to all
, which then triggered callback removal for everything passed to each then
. But to my knowledge, no promise implementations do that. I'm not sure if such a scheme could be correct, predictable, performant, etc.
I believe the function that is directly called on p1
and p2
has to be race
, because it is the only function that has fail-fast behavior, which, if implemented correctly without memory leaks, should remove callbacks it added to promises that haven't resolved. The only other case in which this happens in JS promises is all
in case of rejection, but reason-promise doesn't use rejections, except at the binding level in module Promise.Js
, and, anyway, it wouldn't help, because resolving with Error(_)
is not a rejection at the JS level :) So that all leaves race
as the only choice for a function to call directly on the user's promises.
from promise.
Ahh, thanks for the explanation! I understand now.
from promise.
Related Issues (20)
- Pipe last implementation HOT 2
- Add `Promise.both` HOT 2
- BuckleScript 8.0.0 breaks listToArray / Promise.all HOT 5
- Reduce compiled size again HOT 4
- Format with refmt? HOT 2
- About the deprecation of the infix operators HOT 2
- Promise.allOkArray never resolves if input is an empty array HOT 1
- Tests: remainsPending appears not to be working
- Converting from Js.Promise HOT 3
- Convert tests to OCaml syntax
- Add a js_of_ocaml variant
- Try an internal module with double underscores to hide "rejectable" from error messages
- Exceptions cause resolution with `undefined` HOT 8
- Provide type abbreviation for promises that reject with Js.Promise.error
- Convert README snippets to ReScript syntax
- Convert to ReScript syntax once there is enough adoption HOT 10
- tap on a rejected promise triggers unhandled promise rejection HOT 3
- Native Example HOT 4
- Example for reason syntax with letop
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from promise.