I am trying to use the REPL to perform some asynchronous operations (i.e. communicate with some servers, connect and retrieve data from databases, use "web-socket" like protocols, etc.).
I seem to be unable to get any simple asynchronous operation going. For example:
> var counter = 0
> DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) { counter += 1 }
// counter is always 0
I am not sure whether the problem is any of the following:
- The REPL (as command-line programs) doesn't have a
RunLoop
. - The REPL stops execution completely and waits for more input lines.
I would appreciate if someone knows whether asynchronous operations are actually possible and if so, how.