U vi@sxddlmZddlmZmZmZmZddlmZmZddlm Z ddl m Z m Z ddl mZedZGd d d eZd S) )datetime)CallableOptionalTypeVarcast)abctyping) SchedulerBase) DisposableSingleAssignmentDisposable)PeriodicScheduler_TStatecseZdZejeegefddfdd Ze e dddZ de j eeeejdd d Zde je j eeeejd d d Zde je j eeeejd ddZde je jeeeejdddZejddddZe j ee j edddZeddddZZS)CatchSchedulerN) schedulerhandlerreturncs&t||_||_d|_d|_dS)aWraps a scheduler, passed as constructor argument, adding exception handling for scheduled actions. The handler should return True to indicate it handled the exception successfully. Falsy return values will be taken to indicate that the exception should be escalated (raised by this scheduler). Args: scheduler: The scheduler to be wrapped. handler: Callable to handle exceptions raised by wrapped scheduler. N)super__init__ _scheduler_handler_recursive_original_recursive_wrapper)selfrr __class__S/opt/alt/python38/lib/python3.8/site-packages/reactivex/scheduler/catchscheduler.pyrs  zCatchScheduler.__init__)rcCs|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. )rnow)rrrrr"s zCatchScheduler.now)actionstatercCs||}|jj||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 )_wraprschedule)rrr rrrr#.s zCatchScheduler.schedule)duetimerr rcCs||}|jj|||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!)r"rschedule_relativerr$rr rrrr%?s z CatchScheduler.schedule_relativecCs||}|jj|||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!)r"rschedule_absoluter&rrrr'Ts z CatchScheduler.schedule_absolute)periodrr rcshtjd}t|sttddttttdfdd }ttj}|j |||d_ S) aSchedules a periodic piece of work. Args: period: Period in seconds or timedelta for running the work periodically. action: Action to be executed. state: [Optional] Initial state passed to the action upon the first iteration. Returns: The disposable object used to cancel the scheduled recurring action (best effort). schedule_periodicFN)r rc sXrdSz |WStk rR}z"d|s4WYdSd}~XYnXdS)NT) ExceptionrZdispose)r exrZdispfailedrrrperiodics  z2CatchScheduler.schedule_periodic..periodicr!)N) getattrrcallableNotImplementedErrorr rrrr r)Z disposable)rr(rr r)r.rrr,rr)is $ z CatchScheduler.schedule_periodic)rrcCs t||jSN)rr)rrrrr_cloneszCatchScheduler._clone)rrcs,|tjttttjdfdd }|S)N)rr rc sPz||WStk rJ}z|s0tWYSd}~XYnXdSr2)_get_recursive_wrapperr*rr )rr r+rparentrrwrapped_actions  z,CatchScheduler._wrap..wrapped_action)rr rrDisposableBase)rrr7rr5rr"s  zCatchScheduler._wrapcCs<|jdks|j|kr6||_||}||_||_||_|jSr2)rrr3)rrwrapperrrrr4s z%CatchScheduler._get_recursive_wrapper)N)N)N)N)__name__ __module__ __qualname__rr rr*boolrpropertyrrrZScheduledActionrrr8r#Z RelativeTimer%Z AbsoluteTimer'ZScheduledPeriodicActionr)r3r"r4 __classcell__rrrrr sL      , rN)rrrrrrZ reactivexrZreactivex.abc.schedulerr Zreactivex.disposabler r Zperiodicschedulerr rrrrrrs