# Path: rx/concurrency/timeoutscheduler.py
# class TimeoutScheduler(Scheduler):
#     def __init__(self):
#         self.timer = None
# 
#     def schedule(self, action, state=None):
#         #print("TimeoutScheduler:schedule_now()")
#         scheduler = self
#         disposable = SingleAssignmentDisposable()
#         
#         def interval():
#             #print ("TimeoutScheduler:schedule.interval()")
#             disposable.disposable = action(scheduler, state)
#         self.timer = Timer(0, interval)
#         self.timer.start()
#         def dispose():
#             #print ("TimeoutScheduler:schedule.dispose()")
#             self.timer.cancel()
#         return CompositeDisposable(disposable, Disposable(dispose))
# 
#     def schedule_relative(self, duetime, action, state=None):
#         log.info("TimeoutScheduler:schedule_relative(%s)" % duetime)
#         
#         scheduler = self
#         dt = Scheduler.normalize(duetime)
#         if dt == 0:
#             return scheduler.schedule(action, state)
#         
#         disposable = SingleAssignmentDisposable()
#         def interval():
#             log.info("TimeoutScheduler:schedule_relative.interval()")
#             disposable.disposable = action(scheduler, state)
#         
#         seconds = dt.seconds+dt.microseconds/1000000
#         log.info("timeout: %s" % seconds)
#         self.timer = Timer(seconds, interval)
#         self.timer.start()
# 
#         def dispose():
#             log.debug("TimeoutScheduler:schedule_relative.dispose()")
#             self.timer.cancel()
#         
#         return CompositeDisposable(disposable, Disposable(dispose))
# 
#     def schedule_absolute(self, duetime, action, state=None):
#         #print ("TimeoutScheduler:schedule_absolute(%s)" % duetime)
#         return self.schedule_relative(duetime - self.now(), action, state)


from datetime import datetime, timedelta
from time import sleep
from rx.concurrency import TimeoutScheduler

def test_timeout_now():
    res = TimeoutScheduler.now() - datetime.utcnow()
    assert res < timedelta(microseconds=1000)


def test_timeout_schedule_action():

# Path: rx/concurrency/timeoutscheduler.py
# class TimeoutScheduler(Scheduler):
#     def __init__(self):
#         self.timer = None
# 
#     def schedule(self, action, state=None):
#         #print("TimeoutScheduler:schedule_now()")
#         scheduler = self
#         disposable = SingleAssignmentDisposable()
#         
#         def interval():
#             #print ("TimeoutScheduler:schedule.interval()")
#             disposable.disposable = action(scheduler, state)
#         self.timer = Timer(0, interval)
#         self.timer.start()
#         def dispose():
#             #print ("TimeoutScheduler:schedule.dispose()")
#             self.timer.cancel()
#         return CompositeDisposable(disposable, Disposable(dispose))
# 
#     def schedule_relative(self, duetime, action, state=None):
#         log.info("TimeoutScheduler:schedule_relative(%s)" % duetime)
#         
#         scheduler = self
#         dt = Scheduler.normalize(duetime)
#         if dt == 0:
#             return scheduler.schedule(action, state)
#         
#         disposable = SingleAssignmentDisposable()
#         def interval():
#             log.info("TimeoutScheduler:schedule_relative.interval()")
#             disposable.disposable = action(scheduler, state)
#         
#         seconds = dt.seconds+dt.microseconds/1000000
#         log.info("timeout: %s" % seconds)
#         self.timer = Timer(seconds, interval)
#         self.timer.start()
# 
#         def dispose():
#             log.debug("TimeoutScheduler:schedule_relative.dispose()")
#             self.timer.cancel()
#         
#         return CompositeDisposable(disposable, Disposable(dispose))
# 
#     def schedule_absolute(self, duetime, action, state=None):
#         #print ("TimeoutScheduler:schedule_absolute(%s)" % duetime)
#         return self.schedule_relative(duetime - self.now(), action, state)


# Path: tests/test_timeoutscheduler.py
from datetime import datetime, timedelta
from time import sleep
from rx.concurrency import TimeoutScheduler


def test_timeout_now():
    res = TimeoutScheduler.now() - datetime.utcnow()
    assert res < timedelta(microseconds=1000)


def test_timeout_schedule_action():

    scheduler = TimeoutScheduler()