mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
1.4 KiB
1.4 KiB
name, slug, sourceRef, category, subCategory, playUrl, variantHelpers, similarHelpers, position, signatures
| name | slug | sourceRef | category | subCategory | playUrl | variantHelpers | similarHelpers | position | signatures | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| WaitFor | waitfor | concurrency.go#L112 | core | concurrency | https://go.dev/play/p/t_wTDmubbK3 |
|
|
20 |
|
Runs periodically until a condition is validated. Use WaitFor for simple predicates, or WaitForWithContext when you need context cancellation/timeout inside the predicate. Both return total iterations, elapsed time, and whether the condition became true.
iterations, elapsed, ok := lo.WaitFor(
func(i int) bool {
return i > 5
},
10*time.Millisecond,
time.Millisecond,
)
With context:
iterations, elapsed, ok := lo.WaitForWithContext(
context.Background(),
func(_ context.Context, i int) bool {
return i >= 5
},
10*time.Millisecond,
time.Millisecond,
)