context.go 767 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. package ice
  4. import (
  5. "context"
  6. "time"
  7. )
  8. func (a *Agent) context() context.Context {
  9. return agentContext(a.done)
  10. }
  11. type agentContext chan struct{}
  12. // Done implements context.Context
  13. func (a agentContext) Done() <-chan struct{} {
  14. return (chan struct{})(a)
  15. }
  16. // Err implements context.Context
  17. func (a agentContext) Err() error {
  18. select {
  19. case <-(chan struct{})(a):
  20. return ErrRunCanceled
  21. default:
  22. return nil
  23. }
  24. }
  25. // Deadline implements context.Context
  26. func (a agentContext) Deadline() (deadline time.Time, ok bool) {
  27. return time.Time{}, false
  28. }
  29. // Value implements context.Context
  30. func (a agentContext) Value(interface{}) interface{} {
  31. return nil
  32. }