Skip to Content
Hands-On Reactive Programming with Python
book

Hands-On Reactive Programming with Python

by Romain Picard
October 2018
Intermediate to advanced
420 pages
10h 26m
English
Packt Publishing
Content preview from Hands-On Reactive Programming with Python

Implementation of the subscriber

The subscriber is implemented as a component. It uses two drivers: the tcp_client and stdout. Its implementation is as follows:

def rmux_client(sources):    response = sources.tcp_client.response.share()    tcp_connect = Observable.just(tcp_client.Connect(        host='127.0.0.1', port='8080'    ))    create_observable = (        response        .flat_map(lambda connection:             Observable.just({                'what': 'subscribe',                 'id':42,                 'name': '1234'})            .map(lambda i: json.dumps(i))            .let(frame)            .map(lambda j: tcp_client.Write(                id=connection.id, data=j.encode()))        )    )    console = (        response        .flat_map(lambda connection: connection.observable            .map(lambda i: i.data.decode('utf-8'))            .let(unframe)            .map(lambda i: json.loads(i))            .group_by(lambda i: i['id'])  .flat_map(lambda ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Programming with Design Patterns

Python Programming with Design Patterns

James W. Cooper

Publisher Resources

ISBN: 9781789138726Supplemental Content