An argument of any type to pass to the doWork
function. Though doWork
only accepts a single argument, you can pass multiple values as part of an
anonymous structure. (Or an array, or a class.)
// Does not work: too many arguments.
// threadPool.run(doWork, argument0, argument1, argument2);
// Works: all arguments are combined into one `State` object.
threadPool.run(doWork, { arg0: argument0, arg1: argument1, arg2: argument2 });
// Alternatives that also work, if everything is the correct type.
threadPool.run(doWork, [argument0, argument1, argument2]);
threadPool.run(doWork, new DoWorkArgs(argument0, argument1, argument2));
Any changes made to this object will persist if and when doWork
is called
again for the same job. (See WorkFunction
for instructions on how to do
this.) This is the recommended way to store doWork
's progress.
Caution: after passing an object to doWork
, avoid accessing or modifying
that object from the main thread, and avoid passing it to other threads.
Doing either may lead to race conditions. If you need to store an object,
pass a clone of that object to doWork
.
Alias
alias for
Dynamic