Skip to content

Commit 8664738

Browse files
committed
keep asset registration in init
1 parent dfcffe1 commit 8664738

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/WebIO.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ provider_ijulia = prefetch_provider_file("ijulia.jl")
103103

104104
function __init__()
105105
push!(Observables.addhandler_callbacks, WebIO.setup_comm)
106+
107+
if !isfile(GENERIC_HTTP_BUNDLE_PATH)
108+
error(
109+
"Unable to find WebIO JavaScript bundle for generic HTTP provider; "
110+
* "try rebuilding WebIO (via `Pkg.build(\"WebIO\")`)."
111+
)
112+
end
113+
bundle_key[] = AssetRegistry.register(GENERIC_HTTP_BUNDLE_PATH)
114+
106115
@require IJulia="7073ff75-c697-5162-941a-fcdaad2a7d2a" begin
107116
include_string(@__MODULE__, provider_ijulia.code, provider_ijulia.file)
108117
end

src/providers/generic_http.jl

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ end
1212
Sockets.send(p::WSConnection, data) = writeguarded(p.sock, JSON.json(data))
1313
Base.isopen(p::WSConnection) = isopen(p.sock)
1414

15-
if !isfile(GENERIC_HTTP_BUNDLE_PATH)
16-
error(
17-
"Unable to find WebIO JavaScript bundle for generic HTTP provider; "
18-
* "try rebuilding WebIO (via `Pkg.build(\"WebIO\")`)."
19-
)
20-
end
21-
const bundle_key = AssetRegistry.register(GENERIC_HTTP_BUNDLE_PATH)
15+
# Ref constant because we need to retreive it in __init__
16+
const bundle_key = Ref{String}("")
2217

2318
include(joinpath(@__DIR__, "..", "..", "deps", "mimetypes.jl"))
2419

@@ -111,7 +106,7 @@ function WebIOServer(
111106
else # relative url
112107
string("http://", baseurl, ":", http_port, WebIO.baseurl[])
113108
end
114-
string(base, bundle_key)
109+
string(base, bundle_key[])
115110
end
116111
wait_time = 5; start = time() # wait for max 5 s
117112
while time() - start < wait_time
@@ -144,7 +139,7 @@ function global_server_config()
144139
ws_default = string("ws://", url, ":", http_port, "/webio_websocket/")
145140
ws_url = get(ENV, "WEBIO_WEBSOCKT_URL", ws_default)
146141
# make it possible, to e.g. host the bundle online
147-
bundle_url = get(ENV, "WEBIO_BUNDLE_URL", string(WebIO.baseurl[], bundle_key))
142+
bundle_url = get(ENV, "WEBIO_BUNDLE_URL", string(WebIO.baseurl[], bundle_key[]))
148143
webio_server_config[] = (
149144
url = url, bundle_url = bundle_url,
150145
http_port = http_port, ws_url = ws_url

0 commit comments

Comments
 (0)