Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start_with bug #94

Open
igneus opened this issue Nov 17, 2016 · 1 comment
Open

start_with bug #94

igneus opened this issue Nov 17, 2016 · 1 comment
Assignees

Comments

@igneus
Copy link
Contributor

igneus commented Nov 17, 2016

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)
igneus added a commit to igneus/signaly-notify that referenced this issue Nov 17, 2016
@igneus
Copy link
Contributor Author

igneus commented Nov 20, 2016

I should have added that when I remove the .start_with(-1) part in the Ruby example, it works as expected: it waits two seconds and then starts printing regularly in both colours.

@csjune csjune self-assigned this Jan 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants