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

Function ExampleRace

promise/promise_example_test.go:173–195  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

171}
172
173func ExampleRace() {
174 p1 := New(func(resolve func(string), reject func(error)) {
175 time.Sleep(time.Millisecond * 100)
176 resolve("fast")
177 })
178 p2 := New(func(resolve func(string), reject func(error)) {
179 time.Sleep(time.Millisecond * 300)
180 resolve("slow")
181 })
182
183 pms := []*Promise[string]{p1, p2}
184 p := Race(pms)
185
186 result, err := p.Await()
187 if err != nil {
188 return
189 }
190
191 fmt.Println(result)
192
193 // Output:
194 // fast
195}

Callers

nothing calls this directly

Calls 3

RaceFunction · 0.85
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…