def __init__(self, subscribe): self._subscribe = subscribe self.lock = Lock() # Run extension method initializers added by meta class for init in self.initializers: init(self, subscribe)
def from_iterable(cls, iterable, scheduler=None): """Converts an array to an observable sequence, using an optional scheduler to enumerate the array. 1 - res = rx.Observable.from_iterable([1,2,3]) 2 - res = rx.Observable.from_iterable([1,2,3], rx.Scheduler.timeout) Keyword arguments: :param Observable cls: Observable class :param Scheduler scheduler: [Optional] Scheduler to run the enumeration of the input sequence on. :returns: The observable sequence whose elements are pulled from the given enumerable sequence. :rtype: Observable """ scheduler = scheduler or current_thread_scheduler lock = Lock() def subscribe(observer): iterator = iter(iterable) def action(action1, state=None): try: with lock: item = next(iterator) except StopIteration: observer.on_completed() else: observer.on_next(item) action1(action) return scheduler.schedule_recursive(action) return AnonymousObservable(subscribe)
def __init__(self): super(Subject, self).__init__() self.is_disposed = False self.is_stopped = False self.observers = [] self.exception = None self.lock = Lock()
def __init__(self, *args): if args and isinstance(args[0], list): self.disposables = args[0] else: self.disposables = list(args) self.is_disposed = False self.lock = Lock() super(CompositeDisposable, self).__init__()
def __init__(self, scheduler, disposable): """Initializes a new instance of the ScheduledDisposable class that uses a Scheduler on which to dispose the disposable.""" self.scheduler = scheduler self.disposable = disposable self.is_disposed = False self.lock = Lock() super(ScheduledDisposable, self).__init__()
def __init__(self, scheduler, observer): super(ScheduledObserver, self).__init__(self._next, self._error, self._completed) self.scheduler = scheduler self.observer = observer self.lock = Lock() self.is_acquired = False self.has_faulted = False self.queue = [] self.disposable = SerialDisposable()
def __init__(self, disposable): """Initializes a new instance of the RefCountDisposable class with the specified disposable.""" self.underlying_disposable = disposable self.is_primary_disposed = False self.is_disposed = False self.lock = Lock() self.count = 0 super(RefCountDisposable, self).__init__()
def __init__(self): """Creates a subject that can only receive one value and that value is cached for all future observations.""" super(AsyncSubject, self).__init__() self.is_disposed = False self.is_stopped = False self.value = None self.has_value = False self.observers = [] self.exception = None self.lock = Lock()
def __init__(self, action=None): """Creates a disposable object that invokes the specified action when disposed. Keyword arguments: dispose -- Action to run during the first call to Disposable.dispose. The action is guaranteed to be run at most once. Returns the disposable object that runs the given action upon disposal. """ self.is_disposed = False self.action = action or noop self.lock = Lock()
def __init__(self, value): """Initializes a new instance of the BehaviorSubject class which creates a subject that caches its last value and starts with the specified value. Keyword parameters: value -- Initial value sent to observers when no other value has been received by the subject yet. """ super(BehaviorSubject, self).__init__(self.__subscribe) self.value = value self.observers = [] self.is_disposed = False self.is_stopped = False self.exception = None self.lock = Lock()
def __init__(self, thread_factory=None, exit_if_empty=False): super(EventLoopScheduler, self).__init__() self.is_disposed = False def default_factory(target): t = threading.Thread(target=target) t.setDaemon(True) return t self.lock = Lock() self.thread_factory = thread_factory or default_factory self.thread = None self.timer = None self.condition = threading.Condition(self.lock) self.queue = PriorityQueue() self.ready_list = [] self.next_item = None self.exit_if_empty = exit_if_empty
def __init__(self, buffer_size=None, window=None, scheduler=None): """Initializes a new instance of the ReplaySubject class with the specified buffer size, window and scheduler. Keyword arguments: buffer_size -- [Optional] Maximum element count of the replay buffer. window [Optional] -- Maximum time length of the replay buffer. scheduler -- [Optional] Scheduler the observers are invoked on. """ self.buffer_size = sys.maxsize if buffer_size is None else buffer_size self.scheduler = scheduler or current_thread_scheduler self.window = timedelta.max if window is None else self.scheduler.to_timedelta(window) self.queue = [] self.observers = [] self.is_stopped = False self.is_disposed = False self.has_error = False self.error = None self.lock = Lock() super(ReplaySubject, self).__init__(self.__subscribe)
def from_queue(cls, mpqueue, scheduler=None): scheduler = scheduler or current_thread_scheduler lock = Lock() def subscribe(observer): def action(action1, state=None): with lock: try: # stream is completed # when no event was received for 3 sec item = mpqueue.get(True, 3) observer.on_next(item) action1(action) except StdQueue.Empty: observer.on_completed() return scheduler.schedule_recursive(action) return AnonymousObservable(subscribe)
def __init__(self): self.lock = Lock() # Deferred instance method assignment for name, method in self._methods: setattr(self, name, types.MethodType(method, self))
def __init__(self, parent): self.parent = parent self.is_disposed = False self.lock = Lock()
def __init__(self, parent): self.parent = parent self.lock = Lock()
def __init__(self, subject, observer): self.subject = subject self.observer = observer self.lock = Lock()
def __init__(self): """Gets a scheduler that schedules work as soon as possible on the current thread.""" self.queues = dict() self.lock = Lock()
def __init__(self): self.current = None self.is_disposed = False self.lock = Lock() super(SerialDisposable, self).__init__()