Swan Lake Beta3 is here.
import ballerina/io;

public function main() {
    io:println("Initializing");

    worker A {
        io:println("In worker A");
    }

    io:println("In function worker");

    // A worker (function or named) can use `wait` to wait for a named worker.
    wait A;

    io:println("After wait A");
}

Waiting for Workers

Named workers can continue to execute after the function’s default worker terminates and the function returns. A worker (function or named) can use wait to wait for a named worker.

import ballerina/io;
public function main() {
    io:println("Initializing");
    worker A {
        io:println("In worker A");
    }
    io:println("In function worker");
    wait A;

A worker (function or named) can use wait to wait for a named worker.

    io:println("After wait A");
}
bal run waiting_for_workers.bal
Initializing
In function worker
In worker A
After wait A
import ballerina/io;

public function main() {
    io:println("Initializing");

    worker A {
        io:println("In worker A");
    }

    io:println("In function worker");

    // A worker (function or named) can use `wait` to wait for a named worker.
    wait A;

    io:println("After wait A");
}

Waiting for Workers

Named workers can continue to execute after the function’s default worker terminates and the function returns. A worker (function or named) can use wait to wait for a named worker.

import ballerina/io;
public function main() {
    io:println("Initializing");
    worker A {
        io:println("In worker A");
    }
    io:println("In function worker");
    wait A;

A worker (function or named) can use wait to wait for a named worker.

    io:println("After wait A");
}
bal run waiting_for_workers.bal
Initializing
In function worker
In worker A
After wait A
Subscribe to the newsletter

In the creation of Ballerina, we were inspired by so many technologies. Thank you to all that have come before us (and forgive us if we missed one): Java, Go, C, C++, D, Rust, Haskell, Kotlin, Dart, TypeScript, JavaScript, Python, Perl, Flow, Swift, Elm, RelaxNG, NPM, Crates, Maven, Gradle, Kubernetes, Docker, Envoy, Markdown, GitHub and WSO2.

Cookie Policy

This website uses cookies so that we can provide you with the best user experience. Read our Cookie Policy to find out more.

If you wish to disable cookies you can do so from your browser.

I Understand