subscriptions
authorJames Sedgwick <jsedgwick@fb.com>
Thu, 2 Oct 2014 03:49:37 +0000 (20:49 -0700)
committerAndrii Grynenko <andrii@fb.com>
Wed, 15 Oct 2014 00:48:03 +0000 (17:48 -0700)
commit30d69c32b8f6952ac5c0f4943ef0c5ddb1917fec
tree9cd152c615b8c9e95c64e5f65412ad2190af10ca
parent0606460a10e0e41f9be09552d771ea1ee327f8ee
subscriptions

Summary:
I'm not thrilled with this implementation, but it mostly works. The big bummer is enforcing that Observables are held in shared_ptrs, or rather that enforcing that condition is impossible.
The protected constructor / friended dumb make_shared() pattern is clunky, and it'd be really easy for a subclasser to shoot themselves in the foot or even in the face.

It does seem like maybe Observable should be made an interface again, and all these details should live in a subclass (FanoutObservable?) where the restriction are super obvious. For instance, the langtech AudioStream object doesn't need all this crap because it overrides subscribe() without using the observer list, but it subclasses anyways.

I'm noodling another approach that (if it works) will not require the shared_ptr dancing, but will probably have some additional overhead... the observable would have to keep track of the subscriptions itself.

I like the RAII subscriptions, though perhaps subscriptions should be optional as long as it's clear that your subscription will last forever it you opt out of them.

Thoughts?

Test Plan: added unit

Reviewed By: hans@fb.com

Subscribers: rushix, hannesr, trunkagent, fugalh, mwa, jgehring, fuegen, njormrod, bmatheny

FB internal diff: D1580443
folly/experimental/wangle/concurrent/ThreadPoolExecutor.h
folly/experimental/wangle/concurrent/test/ThreadPoolExecutorTest.cpp
folly/experimental/wangle/rx/Observable.h
folly/experimental/wangle/rx/Observer.h
folly/experimental/wangle/rx/Subject.h
folly/experimental/wangle/rx/Subscription.h
folly/experimental/wangle/rx/test/RxTest.cpp