cl-async icon indicating copy to clipboard operation
cl-async copied to clipboard

Could the REPL run under the event loop?

Open RobBlackwell opened this issue 12 years ago • 4 comments

If I'm working with cl-async interactively from the REPL, and I type something like:

(as:start-event-loop (lambda () (as:delay (lambda () (format t "Timer fired. Exiting.~%")) :time 3)))

Then the REPL blocks for three seconds.

Is there a way to make the REPL (ideally the SLIME REPL) itself run under the event loop so that I can carry on using the REPL without it blocking?

RobBlackwell avatar Jan 20 '13 10:01 RobBlackwell

That would be very useful. A lot of times I spin up another thread if I want the REPL to be available during async programming, but that's not without it's problems.

After thinking about it, I think Swank itself might have to be converted to use cl-async, which I'm guessing might be a bit of a chore. There could also be some issues with that method as well: calling exit-event-loop would end the entire slime session, and if you lose the reference to a server, you wouldn't be able to close it without terminating the session. This is less of a problem right now since you could interrupt the event loop without interrupting the connection to the swank server. There may be more I'm not thinking of as well.

Unless there's a way to tie an event loop into the swank server from the inside (I can't think of a way) this would probably be a lot of work.

Any thoughts?

orthecreedence avatar Jan 20 '13 22:01 orthecreedence

For now I'm using Bordeaux threads to spin up my event loop on a background thread.

If I could find a neat way to add and remove events and use a TCP stream from the foreground thread, that would work for me.

I'll continue to experiment ;-)

On 20 Jan 2013, at 22:48, andrew lyon [email protected] wrote:

That would be very useful. A lot of times I spin up another thread if I want the REPL to be available during async programming, but that's not without it's problems.

After thinking about it, I think Swank itself might have to be converted to use cl-async, which I'm guessing might be a bit of a chore. There could also be some issues with that method as well: calling exit-event-loop would end the entire slime session, and if you lose the reference to a server, you wouldn't be able to close it without terminating the session. This is less of a problem right now since you could interrupt the event loop without interrupting the connection to the swank server. There may be more I'm not thinking of as well.

Unless there's a way to tie an event loop into the swank server from the inside (I can't think of a way) this would probably be a lot of work.

Any thoughts?

— Reply to this email directly or view it on GitHub.

RobBlackwell avatar Jan 21 '13 06:01 RobBlackwell

You may take a look at how I did SLIME REPL integration with Qt event loop in CommonQt, if it's of any help to you: https://github.com/ivan4th/commonqt/blob/master/repl-integration.lisp The most important thing is SLIME-REPL-EVAL-HOOKS, the other code deals with starting event loop thread and passing forms to it / retrieving results in a safe manner.

ivan4th avatar Jan 21 '13 15:01 ivan4th

@ivan4th this is awesome! I'll go through this and let you know if I have any questions. I don't know a lot about slime/swank/Qt so I might be a bit slow parsing the code.

orthecreedence avatar Jan 21 '13 18:01 orthecreedence