Skip to content

Commit aeeaebd

Browse files
authored
Merge pull request #121 from Keno/kf/noimplicitbindings
Don't rely on implicit binding creation of setglobal!
2 parents 700ed57 + 91268e0 commit aeeaebd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/core.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,19 @@ function start! end
11431143

11441144
function start!(mod::Module = Main, ip::IP4 = ip4_cli(Main.ARGS);
11451145
threads::Int64 = 1, router_threads::UnitRange{Int64} = -2:threads)
1146+
1147+
# Inject bindings we will use into the module
1148+
if !isdefined(mod, :server)
1149+
Core.eval(mod, :(global server, data, routes))
1150+
1151+
# Switch to the latest world where the bindings are available
1152+
invokelatest(_start!, mod, ip, threads, router_threads)
1153+
else
1154+
_start!(mod, ip, threads, router_threads)
1155+
end
1156+
end
1157+
1158+
function _start!(mod::Module, ip::IP4, threads::Int64, router_threads::UnitRange{Int64})
11461159
IP = Sockets.InetAddr(parse(IPAddr, ip.ip), ip.port)
11471160
server::Sockets.TCPServer = Sockets.listen(IP)
11481161
mod.server = server
@@ -1210,6 +1223,7 @@ function generate_router(mod::Module, ip::IP4)
12101223
mod.routes = Vector{AbstractRoute}()
12111224
loaded = []
12121225
for name in server_ns
1226+
isdefined(mod, name) || continue
12131227
f = getfield(mod, name)
12141228
T = typeof(f)
12151229
if T <: AbstractExtension

0 commit comments

Comments
 (0)