Coder Social home page Coder Social logo

Comments (3)

akolnati avatar akolnati commented on June 10, 2024

Will ask on Gitter as this a query more than a issue

from fluture.

Avaq avatar Avaq commented on June 10, 2024

Hi, Firstly thanks for the wonderful package.

You're welcome. And thank you! 🎩

how can i return the output of getPackName [to a variable synchronously]

Your question is quite similar to this one: https://stackoverflow.com/questions/50361976/convert-fluture-future-to-folktale-result

The short answer is you cannot. There's actually no abstraction in JavaScript with which you can do this, because it's a restriction of the language itself.

That said, there's a variety of reasonable alternatives.

  1. Access the value in a map or chain, or any other transformation. As long as you need to transform the value somehow, synchronously or asynchronously, there's no reason to extract it from the Future.
  2. Access the value by consuming the Future. You can use various different shapes of callbacks, or even a Promise, to execute a Future and continue operating on its values.
  3. You can use a coroutine to transform the Future in a synchronous-looking way. So this is just like 1, but the code will look more like how you wanted it to look:
    const main = go(function*(){
      const packageName = yield getPackageName("package.json")
      return `The package is named ${packageName}!`;
    });
    Of course, main now is yet another Future, so you still have to consume it in the end. Just like with Promises, once a function is async, the function calling it must also become async, all the way down to the root of your program. The only difference is that a Promise consumes itself, and a Future has to be explicitly consumed, ideally at the root of your program and nowhere else.

Will ask on Gitter as this a query more than a issue

I'm okay with questions being asked here on GitHub. It's just that sometimes it might take a little while longer for me to notice.

from fluture.

akolnati avatar akolnati commented on June 10, 2024

Thanks. This helps a lot

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.