U vi @ s d dl mZ d dlmZmZmZ d dlmZmZ d dlm Z mZ d dl m Z d dlmZ d dl mZ edZG d d d e jZdS ) )abstractmethod)datetime timedeltatimezone)OptionalTypeVar)abctyping) Disposabledefault_now)UTC_ZERO_TStatec @ s e Zd ZdZeedddZedej e ee ejdddZ edejej e ee ejd d dZedejej e ee ejd dd Zdej e ee ejdddZeejedddZeejedddZeejedddZdS ) SchedulerzBase class for the various scheduler implementations in this package as well as the mainloop sub-package. This does not include an implementation of schedule_periodic, refer to PeriodicScheduler. )returnc C s t S )zRepresents a notion of time for this scheduler. Tasks being scheduled on a scheduler will adhere to the time denoted by this property. Returns: The scheduler's current time, as a datetime instance. r )self r N/opt/alt/python38/lib/python3.8/site-packages/reactivex/scheduler/scheduler.pynow s z Scheduler.nowN)actionstater c C s t S )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). NotImplemented)r r r r r r schedule s zScheduler.schedule)duetimer r r c C s t S )au Schedules 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 r r r r r r r schedule_relative0 s zScheduler.schedule_relativec C s t S )ao Schedules 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). r r r r r schedule_absoluteE s zScheduler.schedule_absolutec C s || |}t |tjr|S t S )ap Invoke the given given action. This is typically called by instances of ScheduledItem. Args: action: Action to be executed. state: [Optional] state to be given to the action function. Returns: The disposable object returned by the action, if any; or a new (no-op) disposable otherwise. ) isinstancer DisposableBaser )r r r retr r r invoke_actionZ s zScheduler.invoke_action)valuer c C s( t |tr|t }t |tr$| }|S )aQ Converts time value to seconds. This method handles both absolute (datetime) and relative (timedelta) values. If the argument is already a float, it is simply returned unchanged. Args: value: the time value to convert to seconds. Returns: The value converted to seconds. )r r r r total_secondsclsr" r r r to_secondso s zScheduler.to_secondsc C s2 t |trt| }nt |ts.tj|tjd}|S )aT Converts time value to datetime. This method handles both absolute (float) and relative (timedelta) values. If the argument is already a datetime, it is simply returned unchanged. Args: value: the time value to convert to datetime. Returns: The value converted to datetime. )tz)r r r r fromtimestampr utcr$ r r r to_datetime s zScheduler.to_datetimec C s, t |tr|t }nt |ts(t|d}|S )a Converts time value to timedelta. This method handles both absolute (datetime) and relative (float) values. If the argument is already a timedelta, it is simply returned unchanged. If the argument is an absolute time, the result value will be the timedelta since the epoch, January 1st, 1970, 00:00:00. Args: value: the time value to convert to timedelta. Returns: The value converted to timedelta. )seconds)r r r r r$ r r r to_timedelta s zScheduler.to_timedelta)N)N)N)N)__name__ __module____qualname____doc__propertyr r r r ZScheduledActionr r r r r ZRelativeTimer ZAbsoluteTimer r! classmethodZAbsoluteOrRelativeTimefloatr&