Observable. If the Subje ct was subscribed to the Observable before the
Observers were subscribed to the Subject, then all the data could have been
published before the Observers were registered with the Subject.
The output from this program is:
Set up
Subject Received 2
Function Received (2, datetime.datetime(2019, 5, 21, 17, 0, 2,
196372))
Lambda Received (2, datetime.datetime(2019, 5, 21, 17, 0, 2,
196372))
Received on_next (2, datetime.datetime(2019, 5, 21, 17, 0, 2,
196372))
Subject Received 3
Function Received (3, datetime.datetime(2019, 5, 21, 17, 0, 2,
196439))
Lambda Received (3, datetime.datetime(2019, 5, 21, 17, 0, 2,
196439))
Received on_next (3, datetime.datetime(2019, 5, 21, 17, 0, 2,
196439))
Subject Received 5
Function Received (5, datetime.datetime(2019, 5, 21, 17, 0, 2,
196494))
Lambda Received (5, datetime.datetime(2019, 5, 21, 17, 0, 2,
196494))
Received on_next (5, datetime.datetime(2019, 5, 21, 17, 0, 2,
196494))
Subject Received 7
Function Received (7, datetime.datetime(2019, 5, 21, 17, 0, 2,
196548))
Lambda Received (7, datetime.datetime(2019, 5, 21, 17, 0, 2,
196548))
Received on_next (7, datetime.datetime(2019, 5, 21, 17, 0, 2,
196548))
Data Stream Completed
Received completed notification
Done
As can be seen from this output the numbers 2, 3, 5 and 7 are received by all of
the Observers once the Subject has added the timestamp.
36.6 Observer Concurrency
By default RxPy uses a single threaded model; that is Observables and Observers
execute in the same thread of execution. However, this is only the default as it is the
simplest approach.
It is possible to indicate that when a Observer subscribes to an Observable that it
should run in a separate thread using the scheduler keyword parameter on the
36.5 Subjects in RxPy 435