Giter VIP home page Giter VIP logo

Comments (12)

chebyrash avatar chebyrash commented on August 26, 2024 1

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.

chebyrash avatar chebyrash commented on August 26, 2024 1

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.

elycruz avatar elycruz commented on August 26, 2024 1

Right, I agree.
I'll start up a new branch for it shortly 👍 ,

from promise.

chebyrash avatar chebyrash commented on August 26, 2024

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.

elycruz avatar elycruz commented on August 26, 2024

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.

elycruz avatar elycruz commented on August 26, 2024

Woops, also seems only chrome 76 and up currently supports Promise.allSettled,

from promise.

elycruz avatar elycruz commented on August 26, 2024

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.

elycruz avatar elycruz commented on August 26, 2024

Ah, here is a good description (from the 'allSettled' draft):
https://tc39.es/proposal-promise-allSettled/

from promise.

chebyrash avatar chebyrash commented on August 26, 2024

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.

chebyrash avatar chebyrash commented on August 26, 2024

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.

elycruz avatar elycruz commented on August 26, 2024

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.

chebyrash avatar chebyrash commented on August 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.