temporalio / samples-go

Temporal Go SDK samples
https://docs.temporal.io/docs/go
Other
453 stars 179 forks source link

Add Sample for Typed equivalents for workflow.* functions/interfaces using generics #313

Open ndtretyak opened 9 months ago

ndtretyak commented 9 months ago

Is your feature request related to a problem? Please describe. Currently, there are a lot of interfaces and functions (e.g., side effects and channels) accepting or returning interface{}. I believe that with generics, it is possible to provide Typed equivalents for these interfaces, enhancing type safety.

Describe the solution you'd like For instance, a side effect could take a typed function f and return f() directly instead of some converter.EncodedValue

func TypedSideEffect[T any](ctx Context, f func(ctx Context) T) (T, error)

Describe alternatives you've considered Implement these typed interfaces in my own code.

Quinn-With-Two-Ns commented 8 months ago

We have discussed how generics can make the Go SDK API more type safe. We plan to provide a sample showing how the Go SDK could be wrapped using generics, but we do not plan to add it to the SDK at this time. If the sample receives sufficient interest me may consider graduating it into the SDK in some form, but that is TBD.