Skip to content

Commit

Permalink
update(Timeout): wrap async callback with Context.PreAsyncCall
Browse files Browse the repository at this point in the history
  • Loading branch information
b97tsk committed Jul 4, 2024
1 parent 83a06a3 commit e18982c
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,7 @@ func (ob timeoutObservable[T]) Subscribe(parent Context, o Observer[T]) {

x.Context.Store(c.Context)

if c.WaitGroup != nil {
c.WaitGroup.Add(1)
}

tm := time.AfterFunc(ob.First, func() {
if c.WaitGroup != nil {
defer c.WaitGroup.Done()
}

tm := time.AfterFunc(ob.First, c.PreAsyncCall(func() {
if x.Context.Swap(sentinel) != sentinel {
cancel()

Expand All @@ -77,7 +69,7 @@ func (ob timeoutObservable[T]) Subscribe(parent Context, o Observer[T]) {

o.Error(ErrTimeout)
}
})
}))

ob.Source.Subscribe(c, func(n Notification[T]) {
switch n.Kind {
Expand Down

0 comments on commit e18982c

Please sign in to comment.