RxPy订阅重复的回调函数

时间:2019-05-28 02:37:21

标签: python rx-py

我对Rx相当陌生,现在遇到了下一个问题:具有从ClassB反复触发的回调函数callback_b(self, value),如何从ClassA function_a(self)订阅该函数并传递一个价值吗?

import rx

class ClassA:
  def function_a(self):
    self.b = ClassB()
    observable = rx.create(self.b.callback_b) # idea to create an observable from a function
    observable.subscribe(lambda x: print("emitted value from callback_b " + x))

class ClassB:
  def callback_b(self, value):
    # callback consistently got triggered from time to time
    observable.on_next(value) # not sure how observable should be accessed, but idea to transmit value back to subscriber (ClassA)


ClassA().function_a() # creates instance of ClassB that eventually starts receiving data into callback_b and notify ClassA as it's observer

0 个答案:

没有答案