Skip to content

Commit 0e5a07b

Browse files
authored
Merge pull request #602 from christiansandberg/fixes-for-wx-scheduler
Fix wxscheduler issues
2 parents f35ee16 + 25ba53f commit 0e5a07b

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Diff for: reactivex/scheduler/mainloop/wxscheduler.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ def interval() -> None:
7575
log.debug("timeout wx: %s", msecs)
7676

7777
timer = self._timer_class(interval)
78-
timer.Start( # type: ignore
79-
msecs, self._wx.TIMER_CONTINUOUS if periodic else self._wx.TIMER_ONE_SHOT
80-
)
78+
# A timer can only be used from the main thread
79+
if self._wx.IsMainThread():
80+
timer.Start(msecs, oneShot=not periodic) # type: ignore
81+
else:
82+
self._wx.CallAfter(timer.Start, msecs, oneShot=not periodic) # type: ignore
8183
self._timers.add(timer)
8284

8385
def dispose() -> None:
@@ -99,8 +101,20 @@ def schedule(
99101
The disposable object used to cancel the scheduled action
100102
(best effort).
101103
"""
104+
sad = SingleAssignmentDisposable()
105+
is_disposed = False
106+
107+
def invoke_action() -> None:
108+
if not is_disposed:
109+
sad.disposable = action(self, state)
110+
111+
self._wx.CallAfter(invoke_action)
102112

103-
return self._wxtimer_schedule(0.0, action, state=state)
113+
def dispose() -> None:
114+
nonlocal is_disposed
115+
is_disposed = True
116+
117+
return CompositeDisposable(sad, Disposable(dispose))
104118

105119
def schedule_relative(
106120
self,

0 commit comments

Comments
 (0)