|
105 | 105 |
|
106 | 106 | const _routes = OrderedCollections.LittleDict{Symbol,Route}() |
107 | 107 | const _channels = OrderedCollections.LittleDict{Symbol,Channel}() |
| 108 | +const _routes_lock = ReentrantLock() |
| 109 | +const _channels_lock = ReentrantLock() |
108 | 110 |
|
109 | 111 |
|
110 | 112 | """ |
@@ -230,8 +232,16 @@ function route_ws_request(req, msg::Union{String,Vector{UInt8}}, ws_client) :: S |
230 | 232 | end |
231 | 233 |
|
232 | 234 |
|
233 | | -function Base.push!(collection, name::Symbol, item::Union{Route,Channel}) |
234 | | - Base.delete!(collection, name)[name] = item # this is to ensure that the item is always the last one in the collection |
| 235 | +function Base.push!(collection::OrderedCollections.LittleDict{Symbol,Route}, name::Symbol, item::Route) |
| 236 | + lock(_routes_lock) do |
| 237 | + Base.delete!(collection, name)[name] = item # this is to ensure that the item is always the last one in the collection |
| 238 | + end |
| 239 | +end |
| 240 | + |
| 241 | +function Base.push!(collection::OrderedCollections.LittleDict{Symbol,Channel}, name::Symbol, item::Channel) |
| 242 | + lock(_channels_lock) do |
| 243 | + Base.delete!(collection, name)[name] = item # this is to ensure that the item is always the last one in the collection |
| 244 | + end |
235 | 245 | end |
236 | 246 |
|
237 | 247 |
|
|
386 | 396 | Removes the route with the corresponding name from the routes collection and returns the collection of remaining routes. |
387 | 397 | """ |
388 | 398 | function delete!(key::Symbol) :: Vector{Route} |
389 | | - OrderedCollections.delete!(_routes, key) |
| 399 | + lock(_routes_lock) do |
| 400 | + OrderedCollections.delete!(_routes, key) |
| 401 | + end |
390 | 402 | return routes() |
391 | 403 | end |
392 | 404 |
|
|
397 | 409 | Removes the channel with the corresponding name from the channels collection and returns the collection of remaining channels. |
398 | 410 | """ |
399 | 411 | function delete_channel!(key::Symbol) :: Vector{Channel} |
400 | | - OrderedCollections.delete!(_channels, key) |
| 412 | + lock(_channels_lock) do |
| 413 | + OrderedCollections.delete!(_channels, key) |
| 414 | + end |
401 | 415 | return channels() |
402 | 416 | end |
403 | 417 |
|
|
0 commit comments