You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

set_void_future.go 792 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package future
  2. import (
  3. "time"
  4. )
  5. type SetVoidFuture struct {
  6. err error
  7. isCompleted bool
  8. completeChan chan any
  9. }
  10. func NewSetVoid() *SetVoidFuture {
  11. return &SetVoidFuture{
  12. completeChan: make(chan any),
  13. }
  14. }
  15. func (f *SetVoidFuture) SetVoid() {
  16. f.isCompleted = true
  17. close(f.completeChan)
  18. }
  19. func (f *SetVoidFuture) SetError(err error) {
  20. f.err = err
  21. f.isCompleted = true
  22. close(f.completeChan)
  23. }
  24. func (f *SetVoidFuture) Error() error {
  25. return f.err
  26. }
  27. func (f *SetVoidFuture) IsComplete() bool {
  28. return f.isCompleted
  29. }
  30. func (f *SetVoidFuture) Wait() error {
  31. <-f.completeChan
  32. return f.err
  33. }
  34. func (f *SetVoidFuture) WaitTimeout(timeout time.Duration) error {
  35. select {
  36. case <-f.completeChan:
  37. return f.err
  38. case <-time.After(timeout):
  39. return ErrWaitTimeout
  40. }
  41. }

公共库

Contributors (1)