Documentation for routine start

Documentation for routine start, assembled from the following types:

class Proc::Async

From Proc::Async

(Proc::Async) method start

method start(Proc::Async:D: :$scheduler = $*SCHEDULER:$cwd = $*CWD --> Promise:D)

Initiates spawning of the external program. Returns a promise that will be kept with a Proc object once the external program exits, and that will be broken if the program cannot be started.

If start is called on a Proc::Async object on which it has already been called before, an exception of type X::Proc::Async::AlreadyStarted is thrown.

Note: If you wish to await the Promise and discard its result, using

try await $p.start;

will throw if the program exited with non-zero status, as the Proc returned as the result of the Promise throws when sunk and in this case it will get sunk outside the try. To avoid that, sink it yourself inside the try:

try sink await $p.start;

class Promise

From Promise

(Promise) method start

method start(Promise:U: &code:$scheduler = $*SCHEDULER --> Promise:D)

Creates a new Promise that runs the given code object. The promise will be kept when the code terminates normally, or broken if it throws an exception. The return value or exception can be inspected with the result method.

The scheduler that handles this promise can be passed as a named argument.

There is also a statement prefix start that provides syntactic sugar for this method:

# these two are equivalent: 
my $p1 = Promise.start({ ;#`( do something here ) });
my $p2 = start { ;#`( do something here ) };

class Supply

From Supply

(Supply) method start

method start(Supply:D: &startee --> Supply:D)

Creates a supply of supplies. For each value in the original supply, the code object is scheduled on another thread, and returns a supply either of a single value (if the code succeeds), or one that quits without a value (if the code fails).

This is useful for asynchronously starting work that you don't block on.

Use migrate to join the values into a single supply again.

class Thread

From Thread

(Thread) method start

method start(Thread:U: &codeBool :$app_lifetime = FalseStr :$name = '<anon>' --> Thread:D)

Creates, runs and returns a new Thread. Note that it can (and often does) return before the thread's code has finished running.