RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating –...

56
2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 1 Alejandro R. Mosteo 2017-jun-13 RxAda: An Ada implementation of the ReactiveX API

Transcript of RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating –...

Page 1: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 1

Alejandro R. Mosteo2017-jun-13

RxAda: An Ada implementation of the

ReactiveX API

Page 2: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 2

PREVIOUSLY, IN ADA-EUROPE 2007...

SANCTA: An Ada 2005 General-PurposeArchitecture for Mobile Robotics Research

Page 3: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 3

ABOUT ME

Robotics, Perception, and Real-Time group (RoPeRT)

http://robots.unizar.es/

Universidad de Zaragoza, Spain

Page 4: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 4

CONTENTS

• Motivation

• What is ReactiveX– Language agnostic– Java– Ada

• RxAda– Design challenges/decisions– Current implementation status– Future steps

Page 5: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 5

PERSONAL MOTIVATION

• Android development– Questionable design decisions for

background tasks that interact with the GUI

• Found RxJava– Simpler, saner way of doing multitasking– Documented comprehensively– Very active community in the Rx world

• Achievable in Ada?– Aiming for the RxJava simplicity of use

Page 6: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 6

EVENT-DRIVEN / ASYNCHRONOUS SYSTEMS

<User drags map>↓

Find nearby items↓⌛

Request images↓⌛↓⌛↓⌛↓⌛

Crop/Process image↓⌛

Update GUI markers

Page 7: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 7

OVERVIEW

Event-driven systems↓

Reactive Programming (philosophy)↓

ReactiveX / Rx (specification)↓

Rx.Net, RxJava, RxJS, RxC++, …↓

RxAda

Page 8: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 8

REACTIVE MANIFESTO (2014-sep-16 v2.0)

www.reactivemanifesto.org“(...) we want systems that are Responsive, Resilient, Elastic and Message Driven. We call these Reactive Systems.”

Jonas BonérDave Farley

Roland KuhnMartin Thompson

Page 9: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 9

REACTIVE PROPERTIES

• Responsive– “the cornerstone of usability and utility”

– “reliable upper bounds [on response time]”

– “consistent quality of service”

• Resilient– “responsive in the face of failure”

– “achieved by replication, containment, isolation and delegation”

– “The client of a component is not burdened with handling its failures.”

Page 10: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 10

REACTIVE PROPERTIES

• Elastic– “responsive under varying workload”

– “react to changes in the input rate by increasing or decreasing the resources allocated”

– “no contention points or central bottlenecks”

• Message driven– “rely on asynchronous message-passing (...)

ensures loose coupling”

– “enables load management, elasticity, and flow control”

Page 11: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 11

REACTIVE SYSTEMS & ROBOTICS

DISTRIBUTED CONSENSUS ALGORITHMS

Courtesy of Washington University course CSE481C

Page 12: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 12

ReactiveX ORIGINSJava• There is no “universal” reactive solution• ReactiveX is one among many

– Roots in .NET (Reactive Extensions)– Erik Meijner

Page 13: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 13

GANG OF FOUR’S OBSERVER PATTERN

Page 14: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 14

PUSH-BASED FRAMEWORK

Observable

time

Observersubscribe

on_next(Item)

on_next(Item)

Page 15: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 15

RELATED TECHNOLOGIES

• Callbacks• Futures/Promises (polling)

– asyncProcess.isDone()– asyncProcess.getResult()– Can become unwieldy when futures depend

on other futures

• Ada AI12-0197-1 (generator functions)yield Datum; -- “Queues” a ready datum…for X of Datum_Generator do -- Blocks until data available

Page 16: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 16

Rx NOVELTY

Main selling point: composability

Observable.from(Map.dragEvent).inBackground().do(Map.whoIsNear(event)).doConcurrently (Users.getPicture(id)).do(crop(image)).inGUIthread().do(updateMarker(image)).subscribe()

Page 17: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 17

Rx COMPOSABILITY

• Advantages:– Imperative-like sequences

• NOT executed when declared• Executed for every emitted item (event)

– Abstract-away concerns like:• Low-level tasking

• Synchronization

• Thread-safety

• Concurrent data structures

• [Non-]Blocking I/O

• Callback interactions

Page 18: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 18

Rx CONTRACT

Observable

time

Observersubscribe

on_next

on_next

on_next

on_completed|on_error|none

Page 19: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 19

Rx CONTRACT / MARBLE DIAGRAMS

On_Next* (On_Completed|On_Error)?

• Finite sequence:

Infinite sequence:

• Failed sequence:

In mutual exclusion

time

Page 20: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 20

RxAda DESIGN CONCERNS

• Ease of use (library clients)– Number of instantiations

• Shallow learning curve

– Boilerplate in creation of sequences• Preserve top-bottom order of actions when possible

• Ease of development– Reasonable (?) complexity

• New features• Ongoing maintenance• Attract contributors

– Avoid definite/indefinite multiplicity• Traits-based implementation

Page 21: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 21

RxAda CONTRACT

Requires one instantiation per user type

On_Next* (On_Completed|On_Error)?

Page 22: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 22

CLASSWIDE CONTRACT ALTERNATIVE (DISCARDED)

• Pros :– No user instantiations– Dot notation available for all operators

• Cons :– User view conversions

• Runtime checks only• Code pollution with “downcasts”

– Or some kind of marshalling• Would require instantiations anyway

Page 23: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 23

FLASHBACK: ITEM SEQUENCES

COMPOSABILITY

Observable.from(Map.dragEvent).inBackground().do(Map.whoIsNear(event)).doConcurrently (Users.getPicture(id)).do(crop(image)).inGUIthread().do(updateMarker(image)).subscribe()

Page 24: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 24

COMPOSITION: OPERATORS

• What is that between – Observable– …– …– …– Observer

?• Operators ≈ Observer + ⚙ + Observable

– Arbitrarily long sequences– Apply one operation– Push down the item– Inactive until subscription!

Integers.Observer’Class

Strings.Observable’Class

Image

Integer

String

Page 25: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 25

PREDEFINED OPERATORS (subset)

• Creating– Just, From– Interval, Range

• Transforming– Map, FlatMap– Buffer, Window– Scan

• Filtering– Filter, Last, Skip– Debounce, Sample– Distinct

• Combining– Merge, Zip

• Tasking– Interval, Timer– ObserveOn– SubscribeOn– Delay, Timeout

• Logical– TakeUntil

• Mathematical– Reduce

Page 26: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 26

OPERATOR CONCATENATION (JAVA / C++)

• Java: dot notation – Chains an operator– Returns another observable

• C++: pipe operator “|”• Ada: “&”

Page 27: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 27

TOY EXAMPLE

13

Map(fn): x → fn(x)

Hello, world!

Just

Page 28: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 28

RxAda DESIGN

• Ada syntax:– No anonymous/lambdas → no inline code

• We cannot have boilerplate in the sequence• We must move logic elsewhere (a-la std containers)

– But also...

Page 29: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 29

Ada DOT NOTATION

• First preference, but unusable:– Freezing rules

• All subprograms at top package level• But transforming operators require a second type

– In a child package» Dot notation no longer available

– Instantiate pairs of types» Circular dependencies

• Settled on using the “&” function– Inspired by C++ and comp.lang.ada discussions– Requires “use” for every type mapping

• Same_Type → Same_Type (e.g., Filter) • From_Type → Into_Type (e.g., Map)

Page 30: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 30

• Every second, – take the corresponding integer (1, 2, … ), – Hash its string representation (in bg task)– Print it (in IO task)

FINAL EXAMPLE

Page 31: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 31

FINAL EXAMPLE: REQUISITES

Page 32: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 32

• Every second, – take the corresponding integer (1, 2, … ), – Hash its string representation (in bg)– Print it (in IO task)

FINAL EXAMPLE

Page 33: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 33

WHAT IS HAPPENING?

Page 34: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 34

SETUP PHASE / OPERATOR ANATOMY

From.Observer’Class Into.Observable’Class

Operator’ClassFrom.T Into.T

Page 35: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 35

COMPILE-TIME OPERATOR CONSISTENCY

“&” returns the Observable view of the same OperatorInteger.Observer’Class

Strings.Observable’Class

Strings.Observer’Class

Integer.Observable’Class

&

Image

Value

Distinct “&” for every [ From.Observer

+Into.Observable ]

combination

Page 36: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 36

SUBSCRIPTION ACTIVATION

returns an Operator

calls to Concatenate

calls toSubscribe returns an Observer

Page 37: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 37

SUBSCRIPTION ACTIVATION

Page 38: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 38

WHAT IS HAPPENING?

Page 39: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 39

WHAT IS HAPPENING?

in current task in current task/ Subscribe_On

in current task/ Observe_On

Page 40: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 40

TASKING

Subscribe_OnObserve_OnOp. param.

Page 41: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 41

N-TO-1 PRODUCERS/CONSUMER

Page 42: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 42

1-TO-N PRODUCER/CONSUMERS

Main flow

Concurrent flowsConcurrent

subscriptions

Page 43: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 43

1-TO-N PRODUCER/CONSUMERS

Main flow

Concurrent flows

Page 44: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 44

LESSONS LEARNED

• The good:– Personal goal achieved– Reasonable good-looking, working library– Most complexity under wraps (for clients)

• The not-so-good:– Number of instances needed– Code size, compilation time– “use” for all types involved

Page 45: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 45

FUTURE STEPS

• More operators– Some unimplemented– Obscure variants

• Fix for GNAT GPL 2017– Compilation currently broken– Check fixes to bugs in GPL 2016

• Use in real/testbed project (!)

• Evaluate performance– Impact of copy semantics

Page 46: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 46

THANKS FOR YOUR ATTENTION

https://bitbucket.org/amosteo/rxada/✉ [email protected] @mosteobotic

?

Page 47: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 47

Rx OBSERVABLE / OBSERVER duality

Observable.subscribe

Something that can be observed

Observer.on_next

Something that observes an observable

Page 48: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 48

TRAITS-BASED IMPLEMENTATION

Page 49: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 49

Different “&”!

COMPILE-TIME OPERATOR CONSISTENCY (II)

Integers.Observer’Class

Strings.Observable’Class

Strings.Observer’Class

Strings.Observable’Class

&

Image

Hash

Long_Int.Observer’Class

Strings.Observable’Class

Strings.Observer’Class

Integer.Observable’Class

&

Image

Value

=

=

Typed

Transformer

Typed

& &

Page 50: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 50

Ada GENERICS

• No inline instantiation (nor inference)

• Ada: Explicit instantiations for– Each user type– Each type conversion between user types

• With distinct source/result• Integer → String• String → Integer

Page 51: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 51

USER PACKAGES

Page 52: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 52

Pre-Java 8 (anonymous classes)

Post-Java 8 (inference/lambda/references)

LANGUAGE SUPPORT FOR BOILERPLATE (Java)

Page 53: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 53

OPERATOR TESTS

• Many operators require parameters that are subprograms– Accesses to library level subprograms– Tagged types allow parameterization without

generics

• BTW: Rx is lazy about tasks

Page 54: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 54

“RUNNABLE” PARAMETERS

• Many operators require parameters that are subprograms– Accesses to library level subprograms– Tagged types allow parameterization without

generics

Page 55: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 55

OBSERVABLE EXAMPLE FROM GENERATORprocedure Subscribe (Producer : in out Observable; Consumer : in out Observer’Class) isbegin for Item of Producer.Generator loop Consumer.On_Next(Item); end loop; Consumer.On_Completed;exception when E : others => Consumer.On_Error (Errors.From_Exception(E));end On_Subscribe;

Page 56: RxAda: An Ada implementation of the ReactiveX API · PREDEFINED OPERATORS (subset) • Creating – Just, From – Interval, Range ... – Merge, Zip • Tasking – Interval, Timer

2017-jun-13 - RxAda: An Ada implementation of the ReactiveX API - 56

JUST / FILTER

2 4

Filter(<test>)

2 3 4 51