Code Monkey home page Code Monkey logo

Comments (4)

Adilmrqureshi avatar Adilmrqureshi commented on July 20, 2024 1

I'm pretty sure that the return type of the effect will represent the async nature.

e.g. if you return a promise from an "Effect creating function" then the type signature will be:

Effect.Effect<never, never, Promise<number>>

I personally think adding an API to the library to represent async functionality is redundant and will make the library unnecessarily verbose. Effect is not a functional programming library and it isn't advertised to be. Its a library to add composability to a JS code base.

Watch this video for more details https://www.youtube.com/watch?v=zrNr3JVUc8I, and if you want a more strict functional library than use fp-ts.

from effect.

mikearnaldi avatar mikearnaldi commented on July 20, 2024 1

We had tried a few different options to track the Async Effect, in reality they all lead to worst DX without actually being safe. Namely even a fully Sync type should support a fromCallback combinator to enable usage with APIs that implement CPS, if such function exist it is impossible at the type level to assert that such function is called immediately and not deferred. So at the end we decided that the price of tracking (lack of composability) together with the inherent lack of safety (if Sync has to be complete it can't be safe) we decided that it isn't worth having separated types.

Notice that in general one should only run Effect at the edges of your app, in an app that uses Effect for everything that is a single call to the main effect and in such case the best way to run is directly using runFork, sync execution is a special case that is needed in environments where async execution is impossible and should be considered an edge case, i.e. use runPromise/runFork when you can, use runSync when you really have to.

from effect.

akomm avatar akomm commented on July 20, 2024

You are talking about a different thing. Example:
https://www.effect.website/docs/essentials/creating#effecttrypromise

Promise not encoded in type system, yet try runSync it -> no type error, but runtime error.

from effect.

akomm avatar akomm commented on July 20, 2024

I understand. Thank for you reply.

I've did some experimentation and realized, due to the nature of Promises in JS its hard to really ensure handling them properly, regardless whether you try to make them explicit in the type or not. Any attempt to tackle it leads to unnecessary calls required to ensure it was not left unhandled or it leaves open holes and hence does not remove the unsafe feeling of "is it actually safe to run or not".

I think its simply a natural limitation and manifests itself in different forms, no matter how you try to move it.

I guess I'll close this one then. In case there is any reason to leave this open, just reopen.

Thank you.

from effect.

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.