U vit@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)GEventSchedulerz[A scheduler that schedules work via the GEvent event loop. http://www.gevent.org/ N)geventreturncst||_dS)zCreate a new GEventScheduler. Args: gevent: The gevent module to use; typically ,you would get this by import gevent N)super__init___gevent)selfr __class__^/opt/alt/python38/lib/python3.8/site-packages/reactivex/scheduler/eventloop/geventscheduler.pyrs zGEventScheduler.__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*GEventScheduler.schedule..intervalcsjdddSNF)blockkillrtimerrrdispose8sz)GEventScheduler.schedule..dispose)r rspawnrr )rrrr!r(rrr rrr'rschedule#s  zGEventScheduler.schedule)duetimerrrcsx|}|dkr jdStddfdd }td|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!Usz3GEventScheduler.schedule_relative..intervalz timeout: %scsjdddSr"r$rr&rrr([sz2GEventScheduler.schedule_relative..dispose) Z to_secondsr+r logdebugrZ spawn_laterrr )rr,rrsecondsr!r(rr*rschedule_relative=s  z!GEventScheduler.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_datetimer0now)rr,rrrrrschedule_absolute`s z!GEventScheduler.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. )r1rZget_hubloopr2)rrrrr2us zGEventScheduler.now)N)N)N)__name__ __module__ __qualname____doc__rrrZScheduledActionr rrZDisposableBaser+Z RelativeTimer0Z AbsoluteTimer3propertyrr2 __classcell__rrrrrs0   ' r)loggingrrrrrZ reactivexrZreactivex.disposablerr r Zperiodicschedulerr r getLoggerr-rrrrrs