MCPcopy Create free account
hub / github.com/cloud-native-go/examples / SlowFunction

Function SlowFunction

ch04/future.go:52–68  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

50}
51
52func SlowFunction(ctx context.Context) Future {
53 resCh := make(chan string)
54 errCh := make(chan error)
55
56 go func() {
57 select {
58 case <-time.After(time.Second * 2):
59 resCh <- "I slept for 2 seconds"
60 errCh <- nil
61 case <-ctx.Done():
62 resCh <- ""
63 errCh <- ctx.Err()
64 }
65 }()
66
67 return &InnerFuture{resCh: resCh, errCh: errCh}
68}

Callers 5

TestFutureFunction · 0.85
TestFutureGetTwiceFunction · 0.85
TestFutureConcurrentFunction · 0.85
TestFutureTimeoutFunction · 0.85
TestFutureCancelFunction · 0.85

Calls 1

ErrMethod · 0.65

Tested by 5

TestFutureFunction · 0.68
TestFutureGetTwiceFunction · 0.68
TestFutureConcurrentFunction · 0.68
TestFutureTimeoutFunction · 0.68
TestFutureCancelFunction · 0.68