runAsync

A function that returns a Future object, which is an eventual result of an asynchronous operation

runAsync(function() {}) → returns any

runAsync Argument Reference

callback function

Closure function that returns a result to be resolved.

timeout numeric
Default: 1000

Timeout for the asynchronous process in milliseconds

Links more information about runAsync

Examples sample code invoking the runAsync function

future = runAsync(function(){
	return "Hello World!";
});
writeOutput(future.get());

Expected Result: Hello World!

future = runAsync(function(){
	return 5;
}).then(function(input){
	return input + 2;
});
result = future.get(3); // 3 is timeout(in ms)
writeOutput(result);

Expected Result: 5

future = runAsync(function(){
	return 5;
}).then(function(input){
	return input + 2;
}).error(function(){
	return "Error occurred.";
});
writeOutput(future.get());

Expected Result: 7


Fork me on GitHub