The Start Task onClick handler is defined as
$(#start-task).onClick = function()
{
var taskElem = $(div#tasks > select)
.$append(<option>Task { ++taskNo }
<progress max=100 />
<span.result /></option>);
function onProgress(p100) {
taskElem.$(progress).value = p100;
}
function onDone(taskId) {
taskElem.$(span.result).text = "Done!";
taskElem.$(progress).remove();
}
view.exec_task(taskId, onProgress, onDone);
}
It defines couple of callback functions and calls view.exec_task() with them.
The view.exec_task() native method is implemented in EventHandler::exec_task().
The EventHandler::exec_task() starts worker thread passing taskNo, onProgress and
onDone parameters to it.
Worker thread body is defined in Rust code as:
// worker thread body, simulate time consuming task
fn thread_body(task_no: i32, progress: Value, done: Value)
{
for i in 1..100 {
std::thread::sleep(std::time::Duration::from_millis(100));
progress.call(None, &make_args!(i), None).unwrap(); // report task progress
}
// report task completion,
// we can pass some result data here, for now just taskId
done.call(None, &make_args!(task_no), None).unwrap();
}
As you see it calls passed callback functions.