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 for source and sink function declarations #1065

Closed
alecthomas opened this issue Mar 12, 2024 · 0 comments · Fixed by #1070
Closed

Support for source and sink function declarations #1065

alecthomas opened this issue Mar 12, 2024 · 0 comments · Fixed by #1070
Assignees

Comments

@alecthomas
Copy link
Collaborator

alecthomas commented Mar 12, 2024

Currently every exported function must be a "verb", accepting a request and returning a response, but we need to support declaring sources and sinks (as per the primitives doc) in order to implement PubSub, but also because sometimes you just don't care about the request or response.

That is, we want to be able to accept:

//ftl:verb
func Sink(ctx context.Context, req Request) error {}

//ftl:verb
func Source(ctx context.Context) (Response, error) {}

We could also support neither request nor response, but we don't need this for PubSub.

//ftl:verb
func Foo(ctx context.Context) error {}

(the same should apply in Kotlin)

The missing values can be represented in the schema as Unit, eg.

verb sink(Request) Unit
verb source(Unit) Response

We'll also need to add additional ftl.CallSink() and ftl.CallSource() helpers, and equivalent in Kotlin.

wesbillman added a commit that referenced this issue Mar 14, 2024
Fixes #1065 

SOLVED: Some things to figure out still:

These were solved by assuming anything without a req is a source,
anything without a resp, is a sink, and anything without either is
empty.

1. How to use `Handle` with these new definitions. Since the signature
no longer matches the `Handle` func, what should we do here? The
generated code here will fail:
    ```go
    func main() {
      verbConstructor := server.NewUserVerbServer("time",
        server.Handle(time.Time),
server.Handle(time.Sink), // these both have build errors since they
don't match the expected signature
        server.Handle(time.Source),
      )
plugin.Start(context.Background(), "time", verbConstructor,
ftlv1connect.VerbServiceName, ftlv1connect.NewVerbServiceHandler)
    }
    ```

2. How should we deal with the fact that the generated code doesn't
match the original signature? This also leads to issues using things
like `ftl.callSink` and `ftl.callSource` since the generated code
doesn't match the signature.
    ```go
    // original

    //ftl:verb
    func Source(context.Context) (SourceResp, error) {
    	return SourceResp{}, nil
    }
    
    // generated

    //ftl:verb
    func Source(context.Context, ftl.Unit) (SourceResp, error) {
panic("Verb stubs should not be called directly, instead use
github.com/TBD54566975/ftl/runtime-go/ftl.Call()")
    }
    ```
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 a pull request may close this issue.

2 participants