Comments (4)
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.
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.
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.
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)
- From Discord: Encode optional hex byte array field as empty Uint8Array if undefined
- From Discord: Possible double initialization of a Layer in `Layer` construction
- From Discord: Workaround for Constructor Argument Inference with Optional Class Fields
- From Discord: Questions about SortedSet.fromIterable deduplication behavior HOT 1
- From Discord: Issue with renaming property in union schema
- From Discord: Issue with template literals type in @effect/[email protected] after upgrade
- From Discord: Schema template literal issue after upgrading to @effect/[email protected]
- JSR computability HOT 1
- From Discord: Setting response cookies from RPC calls HOT 2
- From Discord: Clarification on `onExcessProperty: preserve` Behavior: Key Order Not Maintained
- `Cause` pretty printing is broken for multi-line error messages
- Strict pattern matching HOT 7
- From Discord: Request for `Chunk.lastNonEmpty` Method in Code Library
- From Discord: Ensure `Chunk.reverse` Preserves NonEmpty Status in Output
- `Struct.evolve` no compile time error for non function transformers HOT 2
- From Discord: Request to Add `Schema.NonEmptyChunk` HOT 1
- From Discord: Assigning Error Messages to Specific Inputs in Effect/Schema with Hook Resolvers HOT 1
- More precise `dual` signature (prevent type errors/issues) HOT 16
- From Discord: Detecting ParseError in `decode*Sync` for Error Retry Handling in `@tanstack/react-query`
- From Discord: (bug?) TypeError when using discard option with Effect.all HOT 1
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 effect.