Swan Lake Beta3 is here.
import ballerina/io;

int counter = 0;

function demo() returns int|error {
    worker A returns error? {
        // Workers may need to call functions that can return an error.
        // Pairing up of sends and receives guarantees that each send will be
        // received, and vice-versa, provided neither sending nor receiving worker 
        // has failed.
        error? res = foo();
        if res is error {
            return res;
        }
        42 -> function;

    }

    // Send to or receive from failed worker will propagate the failure.
    int x = check <- A;

    return x;
}

function foo() returns error? {
    if counter == 1 {
        return error("maximum count exceeded");
    }

    counter += 1;
}

public function main() returns error? {
    int a = check demo();
    io:println(a);

    int b = check demo();
    io:println(b);
}

Inter-Worker Failure Propagation

Workers may need to call functions that can return an error. Pairing up of sends and receives guarantees that each send will be received, and vice-versa, provided neither sending nor receiving worker has failed. Send to or receive from failed worker will propagate the failure.

import ballerina/io;
int counter = 0;
function demo() returns int|error {
    worker A returns error? {
        error? res = foo();
        if res is error {
            return res;
        }
        42 -> function;

Workers may need to call functions that can return an error. Pairing up of sends and receives guarantees that each send will be received, and vice-versa, provided neither sending nor receiving worker has failed.

    }
    int x = check <- A;

Send to or receive from failed worker will propagate the failure.

    return x;
}
function foo() returns error? {
    if counter == 1 {
        return error("maximum count exceeded");
    }
    counter += 1;
}
public function main() returns error? {
    int a = check demo();
    io:println(a);
    int b = check demo();
    io:println(b);
}
bal run inter_worker_failure_propagation.bal
42
error: maximum count exceeded {}
import ballerina/io;

int counter = 0;

function demo() returns int|error {
    worker A returns error? {
        // Workers may need to call functions that can return an error.
        // Pairing up of sends and receives guarantees that each send will be
        // received, and vice-versa, provided neither sending nor receiving worker 
        // has failed.
        error? res = foo();
        if res is error {
            return res;
        }
        42 -> function;

    }

    // Send to or receive from failed worker will propagate the failure.
    int x = check <- A;

    return x;
}

function foo() returns error? {
    if counter == 1 {
        return error("maximum count exceeded");
    }

    counter += 1;
}

public function main() returns error? {
    int a = check demo();
    io:println(a);

    int b = check demo();
    io:println(b);
}

Inter-Worker Failure Propagation

Workers may need to call functions that can return an error. Pairing up of sends and receives guarantees that each send will be received, and vice-versa, provided neither sending nor receiving worker has failed. Send to or receive from failed worker will propagate the failure.

import ballerina/io;
int counter = 0;
function demo() returns int|error {
    worker A returns error? {
        error? res = foo();
        if res is error {
            return res;
        }
        42 -> function;

Workers may need to call functions that can return an error. Pairing up of sends and receives guarantees that each send will be received, and vice-versa, provided neither sending nor receiving worker has failed.

    }
    int x = check <- A;

Send to or receive from failed worker will propagate the failure.

    return x;
}
function foo() returns error? {
    if counter == 1 {
        return error("maximum count exceeded");
    }
    counter += 1;
}
public function main() returns error? {
    int a = check demo();
    io:println(a);
    int b = check demo();
    io:println(b);
}
bal run inter_worker_failure_propagation.bal
42
error: maximum count exceeded {}
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