MCPcopy
hub / github.com/duke-git/lancet / ExampleAny

Function ExampleAny

promise/promise_example_test.go:146–171  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

144}
145
146func ExampleAny() {
147 p1 := New(func(resolve func(string), reject func(error)) {
148 time.Sleep(time.Millisecond * 250)
149 resolve("fast")
150 })
151 p2 := New(func(resolve func(string), reject func(error)) {
152 time.Sleep(time.Millisecond * 500)
153 resolve("slow")
154 })
155 p3 := New(func(resolve func(string), reject func(error)) {
156 reject(errors.New("error"))
157 })
158
159 pms := []*Promise[string]{p1, p2, p3}
160 p := Any(pms)
161
162 result, err := p.Await()
163 if err != nil {
164 return
165 }
166
167 fmt.Println(result)
168
169 // Output:
170 // fast
171}
172
173func ExampleRace() {
174 p1 := New(func(resolve func(string), reject func(error)) {

Callers

nothing calls this directly

Calls 4

AnyFunction · 0.85
NewMethod · 0.80
AwaitMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…