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

Support alternate receive action #1277

Closed
jclark opened this issue Nov 10, 2023 · 4 comments
Closed

Support alternate receive action #1277

jclark opened this issue Nov 10, 2023 · 4 comments
Assignees
Milestone

Comments

@jclark
Copy link
Collaborator

jclark commented Nov 10, 2023

When send actions can be conditional #1273, it becomes useful to have an alternate-receive-action, analogous to the alternate-wait-action that already exists.

@lochana-chathura
Copy link
Member

For case 1, case 2 and case 3, do we need to omit the error:NoMessageError? case 4 is correct.

function case1() {
    boolean foo = true;

    worker w1 {
        if foo {
            10 -> w2;
        } else {
            20 -> w2;
        }
    }

    worker w2 {
        int|error:NoMessageError a = <- w1 | w1; // is enforcing NoMessageError here correct? 
    }

    _ = wait {a: w1, b: w2};
}
function case2() {
    boolean foo = true;

    worker w1 {
        if foo {
            10 -> w2;
        }
        20 -> w2;
    }

    worker w2 {
        int|error:NoMessageError a = <- w1 | w1; // is enforcing NoMessageError here correct?
    }

    _ = wait {a: w1, b: w2};
}
function case3() {
    boolean foo = true;
    boolean bar = true;

    worker w1 {
        if foo {
            if bar {
                10 -> w2;
            } else {
                20 -> w2;
            }
            
        } else {
            if bar {
                20 -> w2;
            } else {
                30 -> w2;
            }
        } 
        
    }

    worker w2 {
        int|error:NoMessageError a = <- w1 | w1 | w1 | w1; // is enforcing NoMessageError here correct? 
    }

    _ = wait {a: w1, b: w2};
}
function case4() {
    boolean foo = true;
    boolean bar = true;

    worker w1 {
        if foo {
            10 -> w2;
        }
        if bar {
            20 -> w2;
        }
    }

    worker w2 {
        int|error:NoMessageError a = <- w1 | w1; // OK here
    }

    _ = wait {a: w1, b: w2};
}

@jclark
Copy link
Collaborator Author

jclark commented Jan 4, 2024

  1. foo is not const, so compile-time know that it must be one of the two, but not which; we want to avoid error:NoMessage here, but we haven't defined how
  2. second alternate is compile-time guaranteed to produce a value, so no need for error:NoMessage
  3. same as 1

@lochana-chathura
Copy link
Member

I am just updating the issue with the current jBallerina behavior.

  1. foo is not const, so compile-time know that it must be one of the two, but not which; we want to avoid error:NoMessage here, but we haven't defined how

We enforce error:NoMessage for both 1 and 3 cases as we haven't figured out how to avoid it.

  1. second alternate is compile-time guaranteed to produce a value, so no need for error:NoMessage

We fixed this. error:NoMessage is added iff all receives in the alternate receive have the error:NoMessage.

jclark added a commit that referenced this issue May 9, 2024
@jclark
Copy link
Collaborator Author

jclark commented May 9, 2024

The static type of alternative-receive-action isn't right in the spec at the moment. error:NoMessage is included if any of the alternate receives can fail, rather than if all of them can fail. Need to change the definition of failure type to handle this.

Now fixed by 45f08c3

@jclark jclark closed this as completed May 9, 2024
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

No branches or pull requests

2 participants