Files
ice/context.go
Atsushi Watanabe 06922c1601 Refactor agent task runner
- Control blocking tasks by context
- Add tests to check deadlock by calling Close/Restart in
  state change callback
- Remove unnecessary chan
2020-07-05 16:05:45 +09:00

38 lines
669 B
Go

package ice
import (
"context"
"time"
)
func (a *Agent) context() context.Context {
return agentContext(a.done)
}
type agentContext chan struct{}
// Done implements context.Context
func (a agentContext) Done() <-chan struct{} {
return (chan struct{})(a)
}
// Err implements context.Context
func (a agentContext) Err() error {
select {
case <-(chan struct{})(a):
return ErrRunCanceled
default:
return nil
}
}
// Deadline implements context.Context
func (a agentContext) Deadline() (deadline time.Time, ok bool) {
return time.Time{}, false
}
// Value implements context.Context
func (a agentContext) Value(key interface{}) interface{} {
return nil
}