Documentation ¶
Overview ¶
Package takelatest implements redux-saga effects takeLatest.
Example (DebouncedTimeout) ¶
// The latest Take() call will be executed after previous calls are canceled due to the timeout. done := make(chan struct{}) r := &Runner[int]{ Func: func(ctx context.Context, i int) { time.Sleep(1 * time.Second) if ctx.Err() != nil { return } fmt.Print(i) close(done) }, } defer r.Close() r.Take(1) r.Take(2) r.Take(3) r.Take(4) r.Take(5) <-done
Output: 5
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Runner ¶
type Runner[T any] struct { // Func executes the desired work. Observe context cancellation to know // when the next (aka latest) call comes in. Func cannot be replaced // when the Runner is active, you must Close first. Func func(ctx context.Context, params T) // contains filtered or unexported fields }
Runner implements the takeLatest effect from redux-saga. Its zero value consumes the taken message and does nothing with it.
Click to show internal directories.
Click to hide internal directories.