What is the type of issue?
Documentation is confusing
What is the issue?
I'm reading through the documentation for modeling asynchronous effects, and I find the ordering and structure a little tricky at first:
The intro states:
In traditional programming, we often use Promises to handle asynchronous computations. However, dealing with errors in promises can be problematic. By default, Promise only provides the type Value for the resolved value, which means errors are not reflected in the type system. This limits the expressiveness and makes it challenging to handle and track errors effectively.
To overcome these limitations, Effect introduces dedicated constructors for creating effects that represent both success and failure in an asynchronous context: Effect.promise and Effect.tryPromise. These constructors allow you to explicitly handle success and failure cases while leveraging the type system to track errors.
The first documented API is Effect.promise, which looks promising (sorry), but only applies if you have a promise "where you're confident that the asynchronous operation will always succeed". Promise rejections are "defects" if you use Effect.promise. So it seems very limited in usefulness, and doesn't fulfill the enticing intro about how we're going to use the type system to track errors, because we can't track errors with Effect.promise, at least as documented.
Next we've got Effect.tryPromise. This lets us handle rejections, but then says:
By default if an error occurs, it will be caught and propagated to the error channel as as an UnknownException.
So, again, not really using the type system to represent types of rejections. There's a bit about "Customizing Error Handling", which would let me re-map errors, but what if I have a known error that I'm throwing - I guess I need to do an instanceof check in the catch method?
Below this, I see the docs for handling callbacks, which look a lot like the API that I'd want, but they're described as a way to bridge the gap for callback-based code, rather than a way to do things with async.
It seems like using Effect.tryPromise, with the custom catch handler, is the way to do asynchronous computation with typed errors. But the ergonomics seem a bit weird, and it's confusing that the docs kind of hide it, despite the pitch being centered around typed errors for asynchronous work.
Where did you find it?
https://effect.website/docs/guides/essentials/creating-effects#modeling-asynchronous-effects
What is the type of issue?
Documentation is confusing
What is the issue?
I'm reading through the documentation for modeling asynchronous effects, and I find the ordering and structure a little tricky at first:
The intro states:
The first documented API is
Effect.promise, which looks promising (sorry), but only applies if you have a promise "where you're confident that the asynchronous operation will always succeed". Promise rejections are "defects" if you use Effect.promise. So it seems very limited in usefulness, and doesn't fulfill the enticing intro about how we're going to use the type system to track errors, because we can't track errors withEffect.promise, at least as documented.Next we've got
Effect.tryPromise. This lets us handle rejections, but then says:So, again, not really using the type system to represent types of rejections. There's a bit about "Customizing Error Handling", which would let me re-map errors, but what if I have a known error that I'm throwing - I guess I need to do an
instanceofcheck in the catch method?Below this, I see the docs for handling callbacks, which look a lot like the API that I'd want, but they're described as a way to bridge the gap for callback-based code, rather than a way to do things with async.
It seems like using Effect.tryPromise, with the custom catch handler, is the way to do asynchronous computation with typed errors. But the ergonomics seem a bit weird, and it's confusing that the docs kind of hide it, despite the pitch being centered around typed errors for asynchronous work.
Where did you find it?
https://effect.website/docs/guides/essentials/creating-effects#modeling-asynchronous-effects