Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alternate receive bbe #5290

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

poorna2152
Copy link
Contributor

@poorna2152 poorna2152 commented Apr 8, 2024

examples/alternate-receive/alternate_receive.bal Outdated Show resolved Hide resolved

worker w6 returns int|error? {
// Alternate receive action waits until a message that is not an error is received
// when error is not an expected static type. Since `w4` returns an error it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the "error is not an expected static type" part correct?

Also, with

import ballerina/io;
import ballerina/lang.runtime;

public function main() {
    worker w4 returns error? {
        int value = 10;
        if value == 10 {
            return error("Error in worker 1");
        }
        value -> w6;
    }

    worker w5 returns error? {
        runtime:sleep(2);
        boolean b = true;
        if b {
            return error("x");
        }
        3 -> w6;
    }

    worker w6 returns int|error? {
        // Alternate receive action waits until a message that is not an error is received 
        // when error is not an expected static type. Since `w4` returns an error it 
        // waits further and sets the value that is received from `w5`.
        int|error a = <- w4 | w5;
        return a;
    }

    int|error? valueW6 = wait w6;
    io:println(valueW6);
}

when error is in the expected type, we still wait for the second error?

@lochana-chathura

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when error is in the expected type, we still wait for the second error?

I think no.

@HindujaB can u confirm the behavior here?

Copy link
Contributor

@HindujaB HindujaB Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we don't evaluate the error return type when passing the message.
The alternate wait will wait until a message that is not an error is received. Or if errors are received in all the channels, then the result is the last such error.
In the above case, the int|error a = <- w4 | w5; will return error("x").

examples/alternate-receive/alternate_receive.bal Outdated Show resolved Hide resolved
examples/alternate-receive/alternate_receive.md Outdated Show resolved Hide resolved
examples/alternate-receive/alternate_receive.metatags Outdated Show resolved Hide resolved
examples/index.json Outdated Show resolved Hide resolved
examples/alternate-receive/alternate_receive.bal Outdated Show resolved Hide resolved

worker w6 returns int|error? {
// Alternate receive action waits until a message that is not an error is received
// when error is not an expected static type. Since `w4` returns an error it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when error is in the expected type, we still wait for the second error?

I think no.

@HindujaB can u confirm the behavior here?

Copy link
Member

@lochana-chathura lochana-chathura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Co-authored-by: lochana-chathura <39232462+lochana-chathura@users.noreply.github.com>
@poorna2152 poorna2152 force-pushed the alternative_receive branch 2 times, most recently from cbc1f16 to 138bc4b Compare April 18, 2024 08:26
Copy link
Member

@lochana-chathura lochana-chathura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

examples/alternate-receive/alternate_receive.bal Outdated Show resolved Hide resolved
Comment on lines 46 to 53
function fetch(string url) returns json|error {
http:Client cl = check new (url);
map<json> payload = check cl->get("");
return payload["args"];
}

function getJsonProperty(json|error data) returns json|error? =>
data is error ? data.message() : data.'worker;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function fetch(string url) returns json|error {
http:Client cl = check new (url);
map<json> payload = check cl->get("");
return payload["args"];
}
function getJsonProperty(json|error data) returns json|error? =>
data is error ? data.message() : data.'worker;
function fetch(string url) returns map<json>|error {
http:Client cl = check new (url);
record {| map<json> args; |} payload = check cl->/;
return payload.args;
}
function getJsonProperty(map<json>|error data) returns json|error =>
data is error ? data.message() : data.'worker;

Copy link

sonarcloud bot commented Apr 19, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link

github-actions bot commented May 4, 2024

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label May 4, 2024
@poorna2152 poorna2152 removed the Stale label May 7, 2024
Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants