reazen / relude

FP-inspired prelude/standard library for ReasonML projects
https://reazen.github.io/relude
MIT License
268 stars 41 forks source link

IO.summonError not terminating for some cases #181

Closed andywhite37 closed 5 years ago

andywhite37 commented 5 years ago

@mlms13 discovered that something with relude-fetch is not terminating when using IO.summonError. We isoloated one simple case that doesn't terminate:

testAsync("summonError - async flatMap suspend", onDone =>
    IO.async(onDone => onDone(Result.ok(4)))
    |> IO.flatMap(a => IO.suspend(() => a))
    |> IO.summonError
    |> IO.bimap(
         res => expect(res) |> toEqual(Belt.Result.Ok(4)),
         Relude.Void.absurd,
       )
    |> IO.unsafeRunAsync(
         fun
         | Ok(assertion) => onDone(assertion)
         | Error(assertion) => onDone(assertion),
       )
  );

relude-fetch uses IO.suspendIO to interop with promises, so I suspect there's a problem with IO.suspend/IO.suspendIO when combined with IO.summonError. It might be specifically when used with IO.flatMap.

I'll look into this tonight - I imagine it's just a bug in the mess that is summonError.

johnhaley81 commented 5 years ago

Was this on the version with my fix?

andywhite37 commented 5 years ago

Yeah, but I suspect it's just something deeper that is broken - maybe just something with a specific combination of functions.

andywhite37 commented 5 years ago

Possible fix in 0.31.0