U vi@sddlZddlmZmZddlmZmZddlmZddlm Z ddl m Z ddl m Z dd lmZdd lmZed Zed ZGd ddeZdS)N)OptionalTypeVar)abctyping)DisposableBase)ScheduledAction) DELTA_ZERO) ScheduledItem) Scheduler) Trampoline_TStateZRxc@seZdZdZddddZedddZdeje e e ej dd d Z de jeje e e ej d d d Zde jeje e e ej d ddZedddZee e e dddZdS)TrampolineScheduleraRepresents an object that schedules units of work on the trampoline. You should never schedule timeouts using the *TrampolineScheduler*, as it will block the thread while waiting. Each instance has its own trampoline (and queue), and you can schedule work on it from different threads. Beware though, that the first thread to call a *schedule* method while the trampoline is idle will then remain occupied until the queue is empty. N)returncCs t|_dSN)r _trampselfrX/opt/alt/python38/lib/python3.8/site-packages/reactivex/scheduler/trampolinescheduler.py__init__szTrampolineScheduler.__init__cCs|jSr)rrrrrget_trampoline sz"TrampolineScheduler.get_trampoline)actionstatercCs|j|j||dS)a!Schedules an action to be executed. Args: action: Action to be executed. state: [Optional] state to be given to the action function. Returns: The disposable object used to cancel the scheduled action (best effort). r)schedule_absolutenow)rrrrrrschedule#szTrampolineScheduler.schedule)duetimerrrcCs&tt||}|j|j|||dS)auSchedules an action to be executed after duetime. Args: duetime: Relative time after which to execute the action. action: Action to be executed. state: [Optional] state to be given to the action function. Returns: The disposable object used to cancel the scheduled action (best effort). r)maxrZ to_timedeltarr)rrrrrrrschedule_relative3sz%TrampolineScheduler.schedule_relativecCs@||}||jkrtdt||||}|||jS)aoSchedules an action to be executed at duetime. Args: duetime: Absolute time at which to execute the action. action: Action to be executed. state: [Optional] state to be given to the action function. Returns: The disposable object used to cancel the scheduled action (best effort). zDo not schedule blocking work!) to_datetimerlogwarningr rrunZ disposable)rrrrdtitemrrrrHs    z%TrampolineScheduler.schedule_absolutecCs |S)aTest if scheduling is required. Gets a value indicating whether the caller must call a schedule method. If the trampoline is active, then it returns False; otherwise, if the trampoline is not active, then it returns True. )ridlerrrrschedule_requiredcsz%TrampolineScheduler.schedule_required)rrcCs|r||S||dS)z+Method for testing the TrampolineScheduler.N)r(r)rrrrrensure_trampolinems z%TrampolineScheduler.ensure_trampoline)N)N)N)__name__ __module__ __qualname____doc__rr rrrr rrrrZ RelativeTimer Z AbsoluteTimerboolr(r)rrrrrs6     r)loggingrrrZ reactivexrZreactivex.abc.disposablerZreactivex.abc.schedulerrZreactivex.internal.constantsrZ scheduleditemr Z schedulerr Z trampoliner r getLoggerr"rrrrrs