temporalio / samples-go

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

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

Open ndtretyak opened 1 year ago

ndtretyak commented 1 year 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 1 year 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.