Comments (12)
Yes, you are quite right
I think we should research how this method is implemented in another languages since it's only a draft / proposal in JS
from promise.
This actually looks pretty good:
https://github.com/tc39/proposal-promise-allSettled#examples
https://github.com/tc39/proposal-promise-allSettled#real-world-scenarios
from promise.
Right, I agree.
I'll start up a new branch for it shortly 👍 ,
from promise.
Thanks for creating this issue. I read the code from the Race PR where you started working on the AllSettled method. Could you explain the reasoning behind the Result type and why it's needed? Reading the spec I see the following Returns ... an array of objects that each describe the outcome of each promise.
meaning that AllSettled[Promise("hello"), Promise("world"), Promise(willError)]
will return ["hello", "world", someError]
and the user can do a for loop and switch on each element's type
from promise.
Sure, not a problem 👍 .
If you run the example on the mdn site with the following change:
console.log(result.status)
to console.log(result)
you'll see that result
is actually
an object. Link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled
from promise.
Woops, also seems only chrome 76 and up currently supports Promise.allSettled
,
from promise.
Though also, if you see the line (in the example (mdn example)) you'll see they're actually referencing the contained promise status via result.status
(hence what I did)).
from promise.
Ah, here is a good description (from the 'allSettled' draft):
https://tc39.es/proposal-promise-allSettled/
from promise.
I think we should do it your way, the way JS drafted it with the results objects (status, value, reason), so it's consistent and follows the design
from promise.
I've decided to avoid the result object way until we get proper generics in Go 2.0 because the result type is lost due to interface{} return value of the promise.
Right now the user should type switch on the returned value (error or some known-to-user type)
from promise.
Aha, I didn't think about that before haha, yes I agree. Result is lost and is hard to know what is returned unless written in docs (I.e., the only way to know is via docs). Good work 👍 .
from promise.
Thanks a lot for pointing out the way JS implements this.
I definitely want to come back to that when we get generics and the type will no longer be lost.
from promise.
Related Issues (15)
- Promise.all slice
- Promise.all slice HOT 2
- Promise Branching HOT 1
- Any plans to add remainder of JS promise interface to this implementation? HOT 5
- how to support timeout ? HOT 4
- Range over promise.All HOT 2
- Questions: run in parallel and stop HOT 1
- promise.Any does not exist HOT 3
- why did you want promise/future feature in golang ? HOT 1
- Add `All` method to 'promise' package HOT 2
- The error return bug in promise.All function HOT 2
- Can it support to combined with a goroutine pool as the resource of the future using, like the Future In Java? HOT 2
- Add `Race` method to the package HOT 2
- Refactor tests HOT 4
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.