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 708 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package future
  2. import (
  3. "context"
  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(ctx context.Context) error {
  31. select {
  32. case <-f.completeChan:
  33. return f.err
  34. case <-ctx.Done():
  35. return ErrContextCancelled
  36. }
  37. }