File tree 1 file changed +18
-4
lines changed
reactivex/scheduler/mainloop
1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -75,9 +75,11 @@ def interval() -> None:
75
75
log .debug ("timeout wx: %s" , msecs )
76
76
77
77
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
81
83
self ._timers .add (timer )
82
84
83
85
def dispose () -> None :
@@ -99,8 +101,20 @@ def schedule(
99
101
The disposable object used to cancel the scheduled action
100
102
(best effort).
101
103
"""
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 )
102
112
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 ))
104
118
105
119
def schedule_relative (
106
120
self ,
You can’t perform that action at this time.
0 commit comments