Skip to content

Conversation

@maxdml
Copy link
Collaborator

@maxdml maxdml commented Aug 8, 2025

This version of a more flexible RunAsStep interface accepts a closure which only requires a context as first argument:

type GenericStepFunc[R any] func(ctx context.Context) (R, error)

Example usage:

stepCtx, stepCancelFunc := WithTimeout(ctx, 1*time.Millisecond)
defer stepCancelFunc() // Ensure we clean up the context
_, err := RunAsStep[string](stepCtx, func(context context.Context) (string, error) {
    return waitForCancelStep(context)
}) 

The part that's tricky is that we can't use the outer scope context in the step (here, the call to waitForCancel)

This is because we do some context augmentation inside DBOS. And we need to pass our new context to the function.

@maxdml maxdml marked this pull request as ready for review August 8, 2025 23:18
@maxdml maxdml merged commit c965f36 into main Aug 11, 2025
1 check passed
@maxdml maxdml deleted the revamp-step-ux-closures branch August 11, 2025 16:44
This was referenced Aug 11, 2025
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 this pull request may close these issues.

4 participants