Coder Social home page Coder Social logo

Why not thenables? about fluture HOT 3 CLOSED

FbN avatar FbN commented on June 10, 2024
Why not thenables?

from fluture.

Comments (3)

Avaq avatar Avaq commented on June 10, 2024 2

See also #35

from fluture.

dicearr avatar dicearr commented on June 10, 2024

I am probably misunderstanding you but, a Future can be easily turned into a Promise by using Future.promise.


In my opinion, adding a .then method to Futures would be misleading. In case it simply converts the Future into a Promise, could we say that Futures are Thenables? Once you call .then you've already lost the Future. And if we want to keep them as Thenable Futures I imagine it would require a non-straight forward .then implementation that returns a Future. And I don't really know how things like eagerness/laziness and cancellations, would behave in that case. I don't think is worth the burden. But I might be completely wrong here.

I can also imagine it would be confusing for newcomers, and it doesn't really fit in the current API design in which most method have been converted into functions. Although, one could always implement the .then method in user-land.

 Future.prototype.then = function (f, g) { return Future.promise (this).then (f, g); }

from fluture.

FbN avatar FbN commented on June 10, 2024

I agree with you that it will be confusing for newcomers.

The idea comes to my mind building a lib to work with the DB that lazy return Fluture futures. My object implement a fork method, like Fluture operator.

But there is no a standard interface between Fluture (F.lock()()()), my lib (myobject.fork()()) and standard promises (promise.then()).

So I have to discriminate at consume time how to consume the 3 different kind of objects to mix results.

Reasoning about native async/await support, probably a .then method would be a nice interface to implement in any library that can be consumed as promises.

But as you suggest I can add it to Futures myself. So I'm ok with that solution for my project :)

from fluture.

Related Issues (20)

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.