Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
exchange.Go
EventLoop
ctx.subscribe
ctx.poll
ctx.order
ctx.cancel
ctx.orderAsync
ctx.cancelAsync
Subscription
threading
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Server
Server.addr
Server.close
Server.stop
Server.join
Server.pending
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

Waits until the service is closed and no handler is running.

join()
join(timeout)

Examples

Start an HTTP service on a random port, watch the pending requests, then shut it down gracefully.

javascript
function main() { // Port 0 picks a free port; addr() returns the actual address var server = threading.Serve("http://127.0.0.1:0", function (ctx) { Sleep(1000) ctx.write("done") }) Log("listen on", server.addr()) // Output: listen on 127.0.0.1:<random port> // Send a request from another thread while the main thread watches the server threading.Thread(function (addr) { Log("response:", HttpQuery("http://" + addr + "/")) // Output: response: done (about 1 second later) }, server.addr()) Sleep(200) Log("pending:", server.pending()) // Output: pending: 1 (one request is being handled) // Stop accepting connections; requests in flight run to completion server.close() Log("idle:", server.join(5000)) // Output: idle: true (the server is closed and every request has finished) }

Returns

TypeDescription

bool

true when the service is closed and no handler is running; false on timeout.

Arguments

NameTypeRequiredDescription

timeout

number

No

Timeout in milliseconds. Omitted or 0 waits indefinitely (it returns when the strategy stops).

See Also

Remarks

On a service that is still open, join() waits until it is closed, so call close() first.