Suspension - #334
Conversation
Add newlines to line events before appending to the async reader, remove trailing readline when flushing the pushback buffer on resume.
arichiardi
left a comment
There was a problem hiding this comment.
This is worth a couple of tests I think, just to understand how the flow looks like, in general it looks good!
| spill! #(loop [] | ||
| (when-some [s (.pop back)] | ||
| (do (.push front s) (recur))))] | ||
| #js [(fn |
There was a problem hiding this comment.
It is probably worth giving a name to fn just to make the pattern clearer.
There was a problem hiding this comment.
this loop [] is useless it should be
+ spill! #(when-some [s (.pop back)]
+ (do (.push front s) (recur)))]where would you like a name?
There was a problem hiding this comment.
In the fn inside the Javascript array
There was a problem hiding this comment.
well, it's just #(when-some [s (.pop back)] (.push front s) (recur)) ...
| back #js [] | ||
| cb (volatile! nil) | ||
| spill! #(when-some [s (.pop back)] (.push front s) (recur))] | ||
| #js [(fn |
There was a problem hiding this comment.
I mean this line:
(fn
([]
(spill!)
The two-arity we, minor anyways
|
circle failure is due to Node version (change in an error message) |
|
I really really like this patch. One thing I wanted to add though, kind of tangential, is a question: how likely a change like this is going to end up in clojure/clojurescript? Because the unrepl protocol is really cool but this patch requires a big buy-in that might not be accepted over there. I know I don't know the answer I am not the maintainer and I know At the beginning I thought the |
|
@arichiardi The current patch changes what is possible with a lumo REPL by making a call to " It happens that's something leveraged by unrepl but it's of broader use. At the conj this year @anmonteiro asked me to find the smallest change that could make lumo upgradable (because my previous attempts were too large: a new reader, a new main loop and a complected IO iface), this is my best answer so far. |
|
Ok great then, I was sure you had considered this already, just to make it clear, I would talking about to apply the save suspension mechanisms to the In any case, I don't feel confident merging this myself so I'll let Antonio have a look. |
|
So @cgrand kindly explained me that I was completely off. The suspension happens before the REPL invokes the accept function and therefore sorry for the noise and the misunderstanding 😄 |
|
@arichiardi I guess I haven't been that successful in conveying the idea across: when you provide an accept function there's no REPL, the Lumo REPL is never started on the socket (the accept function may happen to be a REPL but it can be anything). |
|
@arichiardi could you reopen this PR has it was closed by a typo on the issue number? |
|
@arichiardi thanks! |
This is a solution to #294.
User code wanting to take control of the repl must evaluate to a suspension request (created with
lumo.repl/suspension-request).When the repl sees a suspension request being returned, instead of printing it and "looping", it suspends itself and yield control to the callback embedded in the suspension request.
Two arguments are passed to this callback: an object satisfying
lumo.repl/AsyncReader(the input stream) and aresumecallback to call when user code reaches completion to resume the repl. This callback take a map with keys:value,:errorand:ns. The repl resumes at the "print" phase.The
AsyncReaderprotocol has been introduced as a platform agnostic interface over streams -- even if it's currently namespaced in lumo.