U
vig @ s d dl Z d dlZd dlmZ d dlmZmZ d dlmZmZ d dlm Z d dl
mZ ddlm
Z
dd lmZ ed
Ze dZG dd
d
eZdS ) N)datetime)OptionalTypeVar)abctyping)
Disposable)default_thread_factory )EventLoopScheduler)PeriodicScheduler_TStateZRxc s e Zd ZdZdeej dd fdd
Zdeje ee e
jdddZdej
eje ee e
jd d
dZdejeje ee e
jd dd
Zdej
eje ee e
jdddZ ZS )NewThreadSchedulerzHCreates an object that schedules each unit of work on a separate thread.N)thread_factoryreturnc s t |pt| _d S N)super__init__r r )selfr __class__ W/opt/alt/python38/lib/python3.8/site-packages/reactivex/scheduler/newthreadscheduler.pyr s
zNewThreadScheduler.__init__)actionstater c C s t | jdd}|||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).
Tr Z
exit_if_empty)r
r schedule)r r r schedulerr r r r s
zNewThreadScheduler.schedule)duetimer r r c C s t | jdd}||||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).
Tr )r
r schedule_relative)r r r r r r r r r 0 s
z$NewThreadScheduler.schedule_relativec C s | |}| j|| j ||dS )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 )to_datetimer now)r r r r dtr r r schedule_absoluteG s
z$NewThreadScheduler.schedule_absolute)periodr r r c s^ |t dd fdd}|}| ddfdd}t|S )a Schedules 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).
N)r c sD dkr rd S j} j| q d S )Ng )waitis_setr
total_seconds)timer disposedsecondsr r timeoutr r runt s
z1NewThreadScheduler.schedule_periodic.