U viL@s~ddlZddlmZddlmZmZmZddlmZmZddlm Z m Z m Z ddl m Z edZed ZGd d d e ZdS) N)datetime)AnyOptionalTypeVar)abctyping)CompositeDisposable DisposableSingleAssignmentDisposable)PeriodicScheduler_TStateZRxcseZdZdZeddfdd Zdejee ee j dddZ dej ejee ee j d d d Zdejejee ee j d d d ZeedddZZS)EventletSchedulerz[A scheduler that schedules work via the eventlet event loop. http://eventlet.net/ N)eventletreturncst||_dS)zCreate a new EventletScheduler. Args: eventlet: The eventlet module to use; typically, you would get this by import eventlet N)super__init__ _eventlet)selfr __class__`/opt/alt/python38/lib/python3.8/site-packages/reactivex/scheduler/eventloop/eventletscheduler.pyrs zEventletScheduler.__init__)actionstatercsJtddfdd }j|ddfdd }tt|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). Nrcsjd_dSNrZ invoke_actionZ disposablerrsadrrrrinterval3sz,EventletScheduler.schedule..intervalcs dSNkillrtimerrrdispose8sz+EventletScheduler.schedule..dispose)r rspawnrr )rrrr!r'rrr rrr&rschedule#s  zEventletScheduler.schedule)duetimerrrcsl|}|dkr jdStddfdd }j||ddfdd }tt|S) 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). grNrcsjd_dSrrrrrrr!Usz5EventletScheduler.schedule_relative..intervalcs dSr"r#rr%rrr'Zsz4EventletScheduler.schedule_relative..dispose)Z to_secondsr*r rZ spawn_afterrr )rr+rrsecondsr!r'rr)rschedule_relative=s z#EventletScheduler.schedule_relativecCs ||}|j||j||dS)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). r) to_datetimer-now)rr+rrrrrschedule_absolute_s z#EventletScheduler.schedule_absolutercCs||jjS)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.rZhubsZget_hubclock)rrrrr/ts zEventletScheduler.now)N)N)N)__name__ __module__ __qualname____doc__rrrZScheduledActionr rrZDisposableBaser*Z RelativeTimer-Z AbsoluteTimer0propertyrr/ __classcell__rrrrrs0   & r)loggingrrrrrZ reactivexrZreactivex.disposablerr r Zperiodicschedulerr r getLoggerlogrrrrrs