-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandoff.go
More file actions
49 lines (41 loc) · 1.03 KB
/
Copy pathhandoff.go
File metadata and controls
49 lines (41 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package flowy
import (
"context"
"errors"
"sync"
"sync/atomic"
"time"
)
// ErrHandoffRequested is returned when execution ends for background handoff.
var ErrHandoffRequested = errors.New("flowy: handoff to background requested")
// ErrHandoffNotCompleted is returned when RequestLocalHandoff times out waiting for checkpoint save.
var ErrHandoffNotCompleted = errors.New("flowy: handoff did not complete before deadline")
const handoffCompletionTimeout = 30 * time.Second
type runSession struct {
cancel context.CancelCauseFunc
done chan struct{}
once sync.Once
err atomic.Pointer[error]
}
func newRunSession(cancel context.CancelCauseFunc) *runSession {
return &runSession{
cancel: cancel,
done: make(chan struct{}),
once: sync.Once{},
err: atomic.Pointer[error]{},
}
}
func (s *runSession) finish(err error) {
s.once.Do(func() {
if err != nil {
s.err.Store(new(err))
}
close(s.done)
})
}
func (s *runSession) completionError() error {
if p := s.err.Load(); p != nil {
return *p
}
return nil
}