Files
lo/docs/data/core-durationx.md
T
Samuel Berthe fa095e4b4f fix(doc): fix go playground demo URL (#832)
* fix(doc): fix go playground demo URL

* fix(doc): add more go playground demo URL
2026-03-06 00:09:59 +01:00

2.3 KiB

name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
name slug sourceRef category subCategory signatures playUrl variantHelpers similarHelpers position
DurationX durationx time.go#L7 core time
func Duration(callback func()) time.Duration
func Duration0(callback func()) time.Duration
func Duration1[T any](callback func() T) (T, time.Duration)
func Duration2[T, U any](callback func() (T, U)) (T, U, time.Duration)
func Duration3[T, U, V any](callback func() (T, U, V)) (T, U, V, time.Duration)
func Duration4[T, U, V, W any](callback func() (T, U, V, W)) (T, U, V, W, time.Duration)
func Duration5[T, U, V, W, X any](callback func() (T, U, V, W, X)) (T, U, V, W, X, time.Duration)
func Duration6[T, U, V, W, X, Y any](callback func() (T, U, V, W, X, Y)) (T, U, V, W, X, Y, time.Duration)
func Duration7[T, U, V, W, X, Y, Z any](callback func() (T, U, V, W, X, Y, Z)) (T, U, V, W, X, Y, Z, time.Duration)
func Duration8[T, U, V, W, X, Y, Z, A any](callback func() (T, U, V, W, X, Y, Z, A)) (T, U, V, W, X, Y, Z, A, time.Duration)
func Duration9[T, U, V, W, X, Y, Z, A, B any](callback func() (T, U, V, W, X, Y, Z, A, B)) (T, U, V, W, X, Y, Z, A, B, time.Duration)
func Duration10[T, U, V, W, X, Y, Z, A, B, C any](callback func() (T, U, V, W, X, Y, Z, A, B, C)) (T, U, V, W, X, Y, Z, A, B, C, time.Duration)
https://go.dev/play/p/LFhKq2vY9Ty
core#time#duration
core#time#durationx
core#concurrency#waitfor
core#retry#attemptwithdelay
core#retry#attemptwhilewithdelay
core#retry#newdebounce
core#retry#newdebounceby
core#retry#newthrottle
core#retry#newthrottleby
core#retry#newthrottlebywithcount
0

Measures execution time of a function. Variants return the elapsed duration alongside 0 to 10 returned values from the function.

// Base variant (no return values): Duration
elapsedOnly := lo.Duration(func() {
    time.Sleep(3 * time.Millisecond)
})
_ = elapsedOnly

// Zero-return variant: Duration0
elapsed := lo.Duration0(func() {
    time.Sleep(10 * time.Millisecond)
})
_ = elapsed

// One-return variant: Duration1
v, dur := lo.Duration1(func() int {
    time.Sleep(5 * time.Millisecond)
    return 123
})
_ = v
_ = dur

// Two-return variant: Duration2
a, b, elapsed2 := lo.Duration2(func() (int, string) {
    time.Sleep(2 * time.Millisecond)
    return 7, "x"
})
_ = a
_ = b
_ = elapsed2