inngest / inngestgo

Durable execution in Go with the Golang Inngest SDK. Write durable functions in your existing app.
https://pkg.go.dev/github.com/inngest/inngestgo
Apache License 2.0
29 stars 3 forks source link

Add parallel steps #51

Closed amh4r closed 2 months ago

amh4r commented 3 months ago

Description

Add parallel steps using a new group.Parallel function. The new group package lives in an experimental directory, where it will remain until we feel it's stable.

func MyFn(ctx context.Context, input inngestgo.Input[any]) (any, error) {
    results := group.Parallel(
        ctx,
        func(ctx context.Context) (any, error) {
            return step.Run(ctx, "1a", func(ctx context.Context) (string, error) {
                return "1a output", nil
            })
        },
        func(ctx context.Context) (any, error) {
            return step.Run(ctx, "1b", func(ctx context.Context) (string, error) {
                return "1b output", nil
            })
        },
    )

    out := make([]string, len(results))
    for i, r := range results {
        if r.Error != nil {
            return nil, r.Error
        }
        out[i] = r.Value.(string)
    }
    return out, nil
}