If you want to create a callback, you can create a Method object. Method objects are a combination of the function and the object instance or module they originate from. You can then call the method using the invoke method.
// Handle completion of long
function wakeMeUpBeforeYouGoGo() {
// Do something here
}
// Create a call back with the method method (jinx!)
doLongRunningTask(method(:wakeMeUpBeforeYouGoGo));
I've tried several times, and I'm unable to figure out what I need to do to be able to invoke the passed callback.
using Toybox.WatchUi as Ui;
using Toybox.System as Sys;
class TestView extends Ui.DataField {
function onLayout(dc) {
}
function onShow() {
}
function compute(info) {
}
function doLongRunningTask(fn) {
invoke(fn); // what to do here?
}
function wakeMeUpBeforeYouGoGo() {
Sys.println("!");
}
//! Update the view
function onUpdate(dc) {
doLongRunningTask(method(:wakeMeUpBeforeYouGoGo));
}
}