import ballerina/io;
function main (string[] args) {
worker w1 {
int iw = 200;
float kw = 5.44;
io:println("[w1] iw: " + iw + " kw: " + kw);
}
}
WorkerWorkers in Ballerina allow developers to delegate their tasks to parallel running threads (workers). Workers can be declared within functions, actions or resources. The logic written inside a worker block is executed in a parallel thread to the default (main) thread. Worker execution starts immediately after invoking the relevant function, action, or resource that encloses the worker(s). |
|
import ballerina/io;
|
|
function main (string[] args) {
worker w1 {
int iw = 200;
float kw = 5.44;
io:println("[w1] iw: " + iw + " kw: " + kw);
}
}
|
Workers in Ballerina allow users to delegate tasks to a new worker thread. |
$ ballerina run worker.bal
[w1] iw: 200 kw: 5.44
|
|