Skip to content

Conversation

@Marpond
Copy link

@Marpond Marpond commented Oct 24, 2025

What changed?
Introduces an abstraction of resetting timers via ResettableTimer in workflows.

Why?
Simplifies common timer patterns where timers need to be updated or extended. Previously, we had to manually cancel the existing timer context, handle CanceledError, and create a new timer. With ResettableTimer, a single Reset() call handles this automatically.

How did you test it?
Added workflow unit tests to ensure functional correctness and deterministic replay behavior.

Potential risks
Low risk. Does not alter current timer behavior, only adds a user-friendly interface built on existing timer primitives.

Copy link
Member

@jakobht jakobht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Added a few suggestions.

I think lets put this in the x/resettabletimer package since it's on top of the basic client


// NewResettableTimer creates a new resettable timer that fires after duration d.
// The timer can be reset using Reset() to restart the countdown.
func NewResettableTimer(ctx Context, d time.Duration) ResettableTimer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should return a struct, generally we want to return structs and accept interfaces. This makes backwards compatability easier

err := f.Get(ctx, nil)
s.NoError(err)
timerFired = true
}).Select(ctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we could check that 5 seconds actually passed (the cadence workflow test framework mocks time, so it should be fine)

// Reset - Cancels the current timer and starts a new one with the given duration.
// If duration is not provided, uses the previous duration.
// If the timer has already fired, Reset has no effect.
Reset(d ...time.Duration)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not take a list if we want 0 or 1, I suggest just always taking the reset interval.

Suggested change
Reset(d ...time.Duration)
Reset(d time.Duration)

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.

2 participants