From 0a699a082b4845f7b60a45a8f2006d3c96d1ffb2 Mon Sep 17 00:00:00 2001 From: fchrstou Date: Wed, 8 Mar 2023 12:32:46 +0100 Subject: [PATCH] Module update --- src/RemoteREPL.jl | 3 ++- src/server.jl | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/RemoteREPL.jl b/src/RemoteREPL.jl index b22427c..ce90b7f 100644 --- a/src/RemoteREPL.jl +++ b/src/RemoteREPL.jl @@ -1,12 +1,13 @@ module RemoteREPL -export connect_repl, serve_repl, @remote, connect_remote +export connect_repl, serve_repl, @remote, connect_remote, putmodule! const DEFAULT_PORT = 27754 const PROTOCOL_MAGIC = "RemoteREPL" const PROTOCOL_VERSION = UInt32(1) const STDOUT_PLACEHOLDER = Symbol("#RemoteREPL_STDOUT_PLACEHOLDER") +const NEWMODULE_CHANNEL = Channel{Module}(1) include("tunnels.jl") include("server.jl") diff --git a/src/server.jl b/src/server.jl index f05c4c4..ea8b682 100644 --- a/src/server.jl +++ b/src/server.jl @@ -8,6 +8,18 @@ mutable struct ServerSideSession display_properties::Dict in_module::Module end +function setmodule!(sss::ServerSideSession, mod::Module) + sss.in_module = mod +end + +function putmodule!(mod::Module) + # empty channel + while isready(NEWMODULE_CHANNEL) + take!(NEWMODULE_CHANNEL) + end + # put new module + put!(NEWMODULE_CHANNEL, mod) +end Base.isopen(session::ServerSideSession) = isopen(session.socket) Base.close(session::ServerSideSession) = close(session.socket) @@ -102,6 +114,7 @@ function evaluate_requests(session, request_chan, response_chan) try request = take!(request_chan) result = eval_message(session, request...) + isready(NEWMODULE_CHANNEL) && setmodule!(session, take!(NEWMODULE_CHANNEL)) if !isnothing(result) put!(response_chan, result) end @@ -285,4 +298,3 @@ function serve_repl(server::Base.IOServer; on_client_connect=nothing) end end end -