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

Clarify about future types used in wait expressions #1174

Closed
SasinduDilshara opened this issue Oct 5, 2022 · 6 comments
Closed

Clarify about future types used in wait expressions #1174

SasinduDilshara opened this issue Oct 5, 2022 · 6 comments
Assignees
Labels
spec/improve Something that should be improved in the spec

Comments

@SasinduDilshara
Copy link
Contributor

Description:

According to the current Ballerina specification under the Wait action topic,

A wait-future-expr is used by a wait-action to refer to the worker to be waited for. Its static type must be future<T> for some T. As elsewhere, a wait-future-expr can use an in-scope worker-name in a variable-reference-expr to refer to named worker.

So according to that future<T> will use as static type of wait-future-expr.
But in Ballerina future<T> | future<U> can be simplifies as future <T|U>. So according to that we can use future<T> | future<U> as the static type of wait-future-expr ryt?. So both future<T> and union of future<T> members can used as static type of wait-future-expr.

So Isn't it better if we update the spec saying,

A wait-future-expr is used by a wait-action to refer to the worker to be waited for. Its static type must be sub type of future<T> for some T. As elsewhere, a wait-future-expr can use an in-scope worker-name in a variable-reference-expr to refer to named worker.
@jclark
Copy link
Collaborator

jclark commented Oct 5, 2022

future<T> | future<U> is not equivalent to future<T|U> just as (function() returns T)|(function() returns U) is not equivalent to function() returns (T|U).

If you still wish to propose a change to the spec, please reopen.

@jclark jclark closed this as completed Oct 5, 2022
@SasinduDilshara
Copy link
Contributor Author

SasinduDilshara commented Oct 7, 2022

Yes. It is not equivalent. my mistake. But I think it is a subtype.
So don't we need to change the spec like

A wait-future-expr is used by a wait-action to refer to the worker to be waited for. Its static type must be sub type of future<T> for some T. As elsewhere, a wait-future-expr can use an in-scope worker-name in a variable-reference-expr to refer to named worker.

@jclark
Copy link
Collaborator

jclark commented Oct 7, 2022

Can you please explain why the spec is in need of improvement here?

@SasinduDilshara
Copy link
Contributor Author

Can you please explain why the spec is in need of improvement here?

if it is changed like that we can allow following code sample also.

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

function fn() {
    worker Producer1 returns boolean|error {
        return true;
    }

    worker Producer2 returns boolean|error {
        return true;
    }

    future<boolean|error>|future<boolean|error> x = Producer1;
    WaitResult r2 = wait {producer: x};
}

According to the spec Currently it should be a compile time error because the type needs to be future<T>.

@jclark
Copy link
Collaborator

jclark commented Oct 8, 2022

But why do you want to do that? It's not a useful example.

Are there useful examples that cannot be handled with #1171?

@jclark jclark self-assigned this Oct 9, 2022
@SasinduDilshara
Copy link
Contributor Author

#1171

Useful examples can be handle.
I understand and agree with your opinion.
Hence, close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec/improve Something that should be improved in the spec
Projects
None yet
Development

No branches or pull requests

2 participants