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

Producer/consumer model for creating streams #747

Open
jclark opened this issue Feb 6, 2021 · 5 comments
Open

Producer/consumer model for creating streams #747

jclark opened this issue Feb 6, 2021 · 5 comments
Labels
Area/Lang Relates to the Ballerina language specification Type/Improvement Enhancement to language design

Comments

@jclark
Copy link
Collaborator

jclark commented Feb 6, 2021

In order to support event streams #440, we need to provide a producer/consumer model for creating streams. This requires a new abstraction, which I will call a queue: a producer strand (often started by a listener) can add to a queue; another strand can create stream from the queue, which it can use to process values added by producer strands to the queue.

These streams will typically be unbounded. One of the design challenges here is to ensure that queues can participate properly in a graceful shutdown.

@jclark
Copy link
Collaborator Author

jclark commented Mar 29, 2022

Might be better to call this pipe.

On second thoughts, I think a better name is channel.

@jclark
Copy link
Collaborator Author

jclark commented Mar 30, 2022

See ballerina-platform/ballerina-library#2821 (comment) for a discussion of why shutdown is difficult.

I think we want to approach this by seeing channels as the module-level counterpart of the worker message passing. Worker message passing is not design to maximize expressiveness. It's designed so that it can be fully analyzed, allowing for diagrams, static checking, and deadlock prevention. There's special syntax and named workers are not first-class, i.e. cannot be passed round as values.

@jclark
Copy link
Collaborator Author

jclark commented Mar 30, 2022

Something like:

channel string demoChannel;

service /graphql on new graphql:Listener(4000) {
    resource function sub messages() returns stream<string> {
        // referencing the channel in an expression context produces a value of type stream<T> where
        // T is the member type of the channel
        return demoChannel;
    }
}

service / on new http:Listener(8080) {
    resource function post addMessage(string msg) returns string {
        msg -> demoChannel;
        return msg;
    }
}

Channels would not be allowed to be public, so you can completely analyze what's going on.

@jclark
Copy link
Collaborator Author

jclark commented Mar 30, 2022

This ties into #736.

@jclark
Copy link
Collaborator Author

jclark commented Oct 21, 2022

I suspect prohibiting public channels would be too restrictive. The challenge then is how to make things analyzable without this restriction.

@anupama-pathirage anupama-pathirage added Type/Improvement Enhancement to language design Area/Lang Relates to the Ballerina language specification labels Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Lang Relates to the Ballerina language specification Type/Improvement Enhancement to language design
Projects
None yet
Development

No branches or pull requests

2 participants