Skip to content

Commit

Permalink
Merge pull request #602 from christiansandberg/fixes-for-wx-scheduler
Browse files Browse the repository at this point in the history
Fix wxscheduler issues
  • Loading branch information
dbrattli authored Mar 7, 2022
2 parents f35ee16 + 25ba53f commit 0e5a07b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions reactivex/scheduler/mainloop/wxscheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ def interval() -> None:
log.debug("timeout wx: %s", msecs)

timer = self._timer_class(interval)
timer.Start( # type: ignore
msecs, self._wx.TIMER_CONTINUOUS if periodic else self._wx.TIMER_ONE_SHOT
)
# A timer can only be used from the main thread
if self._wx.IsMainThread():
timer.Start(msecs, oneShot=not periodic) # type: ignore
else:
self._wx.CallAfter(timer.Start, msecs, oneShot=not periodic) # type: ignore
self._timers.add(timer)

def dispose() -> None:
Expand All @@ -99,8 +101,20 @@ def schedule(
The disposable object used to cancel the scheduled action
(best effort).
"""
sad = SingleAssignmentDisposable()
is_disposed = False

def invoke_action() -> None:
if not is_disposed:
sad.disposable = action(self, state)

self._wx.CallAfter(invoke_action)

return self._wxtimer_schedule(0.0, action, state=state)
def dispose() -> None:
nonlocal is_disposed
is_disposed = True

return CompositeDisposable(sad, Disposable(dispose))

def schedule_relative(
self,
Expand Down

0 comments on commit 0e5a07b

Please sign in to comment.