import ballerina/io;
function demo() returns future<int> {
worker A returns int {
return 42;
}
// Futures and workers are the same thing.
// A reference to a named worker can be implicitly converted into a `future`.
return A;
}
type FuncInt function () returns int;
function startInt(FuncInt f) returns future<int> {
// `start` is sugar for calling a function with a named worker and returning
// the named worker as a `future`.
return start f();
}
public function main() returns error? {
future<int> a = demo();
int b = check wait a;
io:println(b);
future<int> c = startInt(() => 100);
int d = check wait c;
io:println(d);
}
Named workers and futuresFutures and workers are the same thing.
A reference to a named worker can be implicitly converted into a |
import ballerina/io;
function demo() returns future<int> {
worker A returns int {
return 42;
}
return A;
Futures and workers are the same thing.
A reference to a named worker can be implicitly converted into a future
.
}
type FuncInt function () returns int;
function startInt(FuncInt f) returns future<int> {
return start f();
start
is sugar for calling a function with a named worker and returning
the named worker as a future
.
}
public function main() returns error? {
future<int> a = demo();
int b = check wait a;
io:println(b);
future<int> c = startInt(() => 100);
int d = check wait c;
io:println(d);
}
bal run named_workers_and_futures.bal
42
100