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

How to create IO-based custom executors #84

Open
HoneyryderChuck opened this issue Mar 16, 2016 · 1 comment
Open

How to create IO-based custom executors #84

HoneyryderChuck opened this issue Mar 16, 2016 · 1 comment

Comments

@HoneyryderChuck
Copy link

Hi, I haven't found any discussion forum about RxRuby, this is more about how to adapt it for my use case, and not an issue with the library itself. Feel free to redirect me to the correct forum if existing, and I'll gladly re-submit this discussion.

I've been looking into #82, and I've seen that it's possible to pass a custom executor through observe_on call (I haven't found documentation about it, however). I have this use case in which I open custom network clients in a batch like scenario, where my current "baby-executor" caps the number of concurrently open connections. This means that further elements of the collection will have to wait for the connection to be open, all callbacks to be run and the connection to be closed, before proceeding with the consumption.

Is there an example of such a Reactive Observable in the wild, or can you provide documentation about it? My concern is that, everytime I call an operation on the collection, my current implementations reopen connections, i.e. I can't seem to keep the connections open until the end of the observable evaluation:

hosts = %w(host1 host2 ...)

collection = MyCustomObservable.new(hosts) # exposes an ssh connection

# I want that both the #select call as the on_next observer callback run 
# within the same network transaction, instead of 
# open/evaluate select/close/open/on_next/close again
collection = collection.select(&:ipindesiredregion)
collection.subscribe(->(conn) { conn.exec!("weird command") } ...

# trigger?
collection.run!
@HoneyryderChuck
Copy link
Author

So, I've been trying this:

...
require 'rx'
collection = MyEnumerable.new(hosts)
reactive_col = Rx::Observable.of_enumerable(collection, MyScheduler.new)
reactive_col.map { |host| host.cmd(".....

I tried with the CurrentThreadScheduler.instance, and the hosts are instantiated sequentially (as expected). Now, in that scheduler of mine, I'm missing how do to proper schedule the tasks.

module MyScheduler < Rx::LocalScheduler # ?

  # where is the documentation?
  def schedule_recursive_with_state(state, action) # is this the proper callback to overwrite
    # what is the state? what is the action?
    # more important, how do pass each enumerable item to a separate object???
    ...
  end

This part is being rather confusing.

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

1 participant