Fork me on GitHub

hi there! I’ve been playing with with SCI recently in my small ClojureScript toy project (a kind of a computational notebook) and it was exactly what I needed and super easy to integrate. Really impressive work! 😍 It made me wonder: would the current design of SCI allow for passing bindings that execute asynchronously, but appear synchronous (blocking) to the caller? E.g., a program like (do (sleep 2000) (js/alert "Here")) . This is, of course, trivial in Clojure where one can dereference a future (or use the <!! macro in core.async), but it could be possible in ClojureScript if SCI could interrupt on certain bindings, returning control to the caller and providing a continuation. Does this make sense? I’d love a synchronous scripting language that runs in a browser. (I’m more familiar with Clojure than ClojureScript so maybe there’s already a way to achieve this somehow via creative use of core.async or native promises). Any pointers would be welcome 🙏


@chistyakov.artem I think @mauricio.szabo has done something similar in his #chlorine-clover project where he implemented a kind of let macro that accepts promises as bindings. Maybe he could tell you more.


@chistyakov.artem I extracted a working example here: It doesn't even use the promesa library, it's just pure promises.


oh wow, thank you so much @borkdude! I’ll look into this more tonight. The gist you shared is much better than what I have right now. I guess, your answer also implies that currently there’s no way to “abstract the async away” from the user like in my original sleep/alert example, is that correct? I realize it might be out of scope for SCI, but it’s one of those things that seem possible in abstract 🙂


Sci doesn't have anything for this at the moment

👍 3

Yeah, what I did was to simulate the p/let from promesa into SCI. I was thinking if it should be possible to eval form by form and, if one return promises, await for it to resolve. This would remove the need for the let binding for SCI too 🙂


reminds me of a thing I’ve promised you @borkdude


@mkvlr No worries, it's not a trivial problem to achieve a solution for ;)