Adds a spawn function to run asynchronous tasks. The task
function passed to spawn can take an Interrupted argument,
which is merely a method that returns true if the task should
stop doing work. Likewise, spawn returns an Interrupt
function that causes the Interrupted function to return true.
One use of spawn is to run asynchronous tasks from
useEffect blocks. The returned Interrupt functions can
serve as the useEffect cleanup function or be called from
the cleanup function.
Note that there's nothing magical about Interrupt—the
task must check Interrupted after every await to see
if it has been interrupted.
Adds a
spawn
function to run asynchronous tasks. The task function passed tospawn
can take anInterrupted
argument, which is merely a method that returnstrue
if the task should stop doing work. Likewise,spawn
returns anInterrupt
function that causes theInterrupted
function to returntrue
.One use of
spawn
is to run asynchronous tasks fromuseEffect
blocks. The returnedInterrupt
functions can serve as theuseEffect
cleanup function or be called from the cleanup function.Note that there's nothing magical about
Interrupt
—the task must checkInterrupted
after everyawait
to see if it has been interrupted.