Skip to content

Commit

Permalink
feat: add Done to test state
Browse files Browse the repository at this point in the history
  • Loading branch information
jizhuozhi committed Aug 3, 2024
1 parent 4153934 commit 1dc2b08
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions future.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func (p *Promise[T]) Future() *Future[T] {
return &Future[T]{state: &p.state}
}

func (p *Promise[T]) Done() bool {
return isDone(atomic.LoadUint64(&p.state.state))
}

func (f *Future[T]) Get() (T, error) {
return f.state.get()
}
Expand All @@ -158,6 +162,10 @@ func (f *Future[T]) Subscribe(cb func(val T, err error)) {
f.state.subscribe(cb)
}

func (f *Future[T]) Done() bool {
return isDone(atomic.LoadUint64(&f.state.state))
}

func isFree(st uint64) bool {
return ((st & maskState) >> 32) == stateFree
}
Expand Down

0 comments on commit 1dc2b08

Please sign in to comment.