A function that returns a Future object, which is an eventual result of an asynchronous operation
runAsync(function() {})
returns any
Name | Type | Required | Default | Description |
---|---|---|---|---|
callback | function | No | Closure function that returns a result to be resolved. | |
timeout | numeric | No | 1000 | Timeout for the asynchronous process in milliseconds |
future = runAsync(function(){
return "Hello World!";
});
writeOutput(future.get());
future = runAsync(function(){
return 5;
}).then(function(input){
return input + 2;
});
result = future.get(3); // 3 is timeout(in ms)
writeOutput(result);
future = runAsync(function(){
return 5;
}).then(function(input){
return input + 2;
}).error(function(){
return "Error occurred.";
});
writeOutput(future.get());