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

Allow alternative wait action inside in a multiple wait action #1171

Open
SasinduDilshara opened this issue Sep 23, 2022 · 3 comments
Open
Labels
enhancement Enhancement to language design lang Relates to the Ballerina language specification
Milestone

Comments

@SasinduDilshara
Copy link
Contributor

SasinduDilshara commented Sep 23, 2022

Description:

Consider the following code.

import ballerina/log;

type WaitResult record {|
    boolean|error producer;
    boolean consumer;
|};

public function main() {
    log:printInfo("initializing app...");

    // Producer 1
    worker Producer1 returns boolean|error {
        int i = 100;
        i -> Consumer;
        error? unionResult = flush Consumer;
        log:printInfo("Sent item", i = i);
        return true;
    }

    worker Producer2 returns boolean|error {
        int i = 100;
        i -> Consumer;
        error? unionResult = flush Consumer;
        log:printInfo("Sent item", i = i);
        return true;
    }

    // Consumer
    worker Consumer returns boolean {
        int i = <- Producer;
        log:printInfo("Received item", i = i);
        return false;
    }

    WaitResult res = wait {producer: Producer1|Producer2, consumer: Consumer};
    log:printInfo("Worker execution finished", result = res);
}

Do we allow following code to run without compiler error?
WaitResult res = wait {producer: Producer1|Producer2, consumer: Consumer};

Related Issues:

ballerina-platform/ballerina-lang#34821

@SasinduDilshara
Copy link
Contributor Author

SasinduDilshara commented Sep 23, 2022

As I understood, currently the Ballerina spec support only for future<T> or in-scope worker-name in a variable-reference-expr to refer to named worker inside the multiple wait actions.
But I think we need to add support for alternative wait actions inside the multiple wait statements.

WDYT?

@SasinduDilshara SasinduDilshara added spec/improve Something that should be improved in the spec lang Relates to the Ballerina language specification labels Sep 23, 2022
@jclark jclark changed the title Clarify about alternative wait action inside in a multiple wait action Allow alternative wait action inside in a multiple wait action Sep 24, 2022
@jclark jclark added enhancement Enhancement to language design and removed spec/improve Something that should be improved in the spec labels Sep 24, 2022
@jclark
Copy link
Collaborator

jclark commented Sep 24, 2022

I think the spec is clear that this is not allowed.

I guess the spec could be enhanced to allow this. Probably, one would want to allow nesting of alternative and multiple waits in a general way.

Unless this is something we are finding that real users need, I would not give this a high priority.

@jclark jclark added this to the Later milestone Sep 24, 2022
@sanjiva
Copy link
Contributor

sanjiva commented Sep 25, 2022

Being able to wait for k out of n workers (which are in an array) to complete is very useful. Simplest case is to make concurrent calls to 2 services and take the first result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to language design lang Relates to the Ballerina language specification
Projects
None yet
Development

No branches or pull requests

3 participants