U vi- @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)TwistedSchedulerzAA scheduler that schedules work via the Twisted reactor mainloop.N)reactorreturncst||_dS)zCreate a new TwistedScheduler. Args: reactor: The reactor to use; typically, you would get this by from twisted.internet import reactor N)super__init___reactor)selfr __class___/opt/alt/python38/lib/python3.8/site-packages/reactivex/scheduler/eventloop/twistedscheduler.pyrs zTwistedScheduler.__init__)actionstatercCs|jd||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_relative)rrrrrrschedule szTwistedScheduler.schedule)duetimerrrcshtd|}tddfdd }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). rNrcs_dSN)Z disposabler)rsadrrrrintervalFsz4TwistedScheduler.schedule_relative..intervalz timeout: %scsjsdSr!)calledcancelr)timerrrdisposeLsz3TwistedScheduler.schedule_relative..dispose) maxZ to_secondsr logdebugrZ callLaterrr )rrrrsecondsr#r'r)rr"rrr&rr0s z"TwistedScheduler.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_datetimernow)rrrrrrrschedule_absoluteRs z"TwistedScheduler.schedule_absoluter cCs|t|jS)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,floatrr+)rrrrr-gs zTwistedScheduler.now)N)N)N)__name__ __module__ __qualname____doc__rrrZScheduledActionr rrZDisposableBaserZ RelativeTimerZ AbsoluteTimer.propertyrr- __classcell__rrrrrs0   & r)loggingrrrrrZ reactivexrZreactivex.disposablerr r Zperiodicschedulerr r getLoggerr)rrrrrs