Async

Hush also provides a way to launch commands asynchronously, and then wait for their result at a later time. Traditional shells provide similar functionality through the ampersand operator.

To run a command block asynchronously, prefix it with an ampersand:

  1. let handle = &{ echo Hello world! }
  2. # Do some other work before calling join.
  3. # This may be printed before or after "Hello world!".
  4. std.print("Doing some work...")
  5. # This will wait until the block runs to completion, and will return it's result.
  6. let result = handle.join()
  7. std.assert(result == nil)

Async blocks will start executing immediately, but Hush won’t wait for their completion until join is called, and will continue script execution instead. An async block will always result in a dict containing the join method, which will then return the block result (nil or error) when called.