Skip to content

start_with bug #94

Description

@igneus

There seems to be a bug in the Ruby implementation of start_with. The two examples below, one written using RxRb, the other using RxPy, construct the same observable, emitting a number every two seconds. To the observable two observers are subscribed, which print the received value in colour. While the Python code prints a series of numbers in both colours, the Ruby code only produces yellow numbers - the blue observer never receives it's input.

Ruby example

require 'colorize'
require 'rx'

observable =
  Rx::Observable
  .interval(2)
  .start_with(-1)

observable.subscribe {|i| puts i.to_s.colorize(:yellow) }
observable.subscribe {|i| puts i.to_s.colorize(:blue) }

while Thread.list.size > 1
  (Thread.list - [Thread.current]).each &:join
end

Python example

import asyncio
import rx
import time
from termcolor import colored

class ColouredObserver:
    def __init__(self, colour):
        self.colour = colour
        
    def on_next(self, x):
        self._print("Got: %s" % x)
        
    def on_error(self, e):
        self._print("Got error: %s" % e)
        
    def on_completed(self):
        self._print("Sequence completed")

    def _print(self, what):
        print(colored(what, self.colour))

observable = rx.Observable.interval(2000).start_with(-1)

observable.subscribe(ColouredObserver('yellow'))
observable.subscribe(ColouredObserver('blue'))

time.sleep(20)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions