Interested in ReScript until I read async/await docs

Are you replying to me?

I said having more complex examples we have here procured on the docs page or a cookbook is always helpful. Im unsure how far OP dove to find examples but doesn’t hurt to consider.

I’m also assessing Rescript right now and I came up with writing a little prelude where I wrap a Belt.Result in a Js.Promise in a dedicated data type for which I wrote a few helper functions :

There’s a very basic usage example here : but I tried it on a much more complex logic flow and it worked smoothely.

If you want to combine promises with results, you might be interested in aantron/promise, it works quite well!


Actually using result is a good thing. I encourage converting promise value to result as soon as possible and avoid using promise catch. There are a lot of good articles about separation of error and exeption flows.
But it’s better to not create a new result type for async operations, and use an existing one with some utility functions for convinient work with promise.
Personally I dont use any library for it. I only use Belt.Result inside of thenResolve and one extra function:

// ResultExtra.res
let asyncFlatMap = (
  self: result<'value, 'error>,
  fn: 'value => Promise.t<result<'newValue, 'error>>,
): Promise.t<result<'newValue, 'error>> => {
  switch self {
  | Error(_) as error => error->Promise.resolve
  | Ok(value) => fn(value)