Is there a way to do async in ReasonML without Promises?


#1

There are times when I might want to do something asynchronously as I’m coding. Is there a native way to do async in ReasonML?


#2

I found this chapter in “Real World OCaml” about how OCaml handles async. LOVE IT. Is this possible in ReasonML? If not, when?

https://realworldocaml.org/v1/en/html/concurrent-programming-with-async.html


#3

Closely related to this, I’ve been wondering what the story/roadmap is for async/await. Any news?


#4

If you compile to native code or to javascript with js_of_ocaml it is possible to use Lwt or Async from Reason.


#5

callbacks work great!
async/await is definitely on the table, will probably be solidified within the next several months


#6

Callbacks are definitely still useful. Here is an example of using callbacks to implement an, asynchronous, recursive loop: https://github.com/scull7/bs-sql-common/blob/55ee425efb6cdc640e4f5abcf40f36ba488945df/src/SqlCommonBatch.ml#L55


#7

If js_of_ocaml supports it so you can use Lwt or Async. Because remember, reason is a syntax, it can do everything Ocaml can.

There are some efforts for this here https://github.com/aantron/repromise and here https://github.com/wokalski/vow


#8

Yes definitely! Reason works just fine with Lwt and Async.


#9

Noooooo! Please don’t build promises into the language. There are lots of issues with them. https://medium.com/@avaq/broken-promises-2ae92780f33

We shouldn’t shove Promises into Reason just because they are familiar to JavaScript developers. I think we should take a step back and consider what solution would be best for a (mostly pure) functional language.


#10

There’s definitely a balance between top-down (“rethink what would be pure”) and bottom-up (“accommodate what people need now”).
async/await doesn’t necessarily mean “unsound js promises” – there’s still lots of experimentation to do.


#11

I’m glad to hear that. It is indeed a difficult balance, and I think you guys have walked the line of practicality vs purity pretty well! I was excited by Elm initially by they favor the first approach way to much and make it impossible to get anything interesting done.

My only concern are that promises are just one of those things that have the potential to leak into every part of the ecosystem and be difficult to back out of if they’re done wrong, so I freaked out a little when I saw that async/await might be added to the language.

p.s., I found your proposal, so I’ll go ahead and rant there. :smiley: