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

Function New

promise/promise.go:30–45  ·  view source on GitHub ↗

New create a new promise instance.

(runnable func(resolve func(T), reject func(error)))

Source from the content-addressed store, hash-verified

28
29// New create a new promise instance.
30func New[T any](runnable func(resolve func(T), reject func(error))) *Promise[T] {
31 if runnable == nil {
32 panic("runnable function should not be nil")
33 }
34
35 p := &Promise[T]{
36 runnable: runnable,
37 pending: true,
38 mu: &sync.Mutex{},
39 wg: &sync.WaitGroup{},
40 }
41
42 defer p.run()
43
44 return p
45}
46
47func (p *Promise[T]) run() {
48 p.wg.Add(1)

Callers 15

ExampleNewFunction · 0.70
ExampleThenFunction · 0.70
ExamplePromise_ThenFunction · 0.70
ExampleCatchFunction · 0.70
ExamplePromise_CatchFunction · 0.70
ExampleAllFunction · 0.70
ExampleAnyFunction · 0.70
ExampleRaceFunction · 0.70
TestThenFunction · 0.70
TestPromise_ThenFunction · 0.70
TestCatchFunction · 0.70
TestPromise_CatchFunction · 0.70

Calls 1

runMethod · 0.95

Tested by 15

ExampleNewFunction · 0.56
ExampleThenFunction · 0.56
ExamplePromise_ThenFunction · 0.56
ExampleCatchFunction · 0.56
ExamplePromise_CatchFunction · 0.56
ExampleAllFunction · 0.56
ExampleAnyFunction · 0.56
ExampleRaceFunction · 0.56
TestThenFunction · 0.56
TestPromise_ThenFunction · 0.56
TestCatchFunction · 0.56
TestPromise_CatchFunction · 0.56