Skip to content

Latest commit

 

History

History
54 lines (34 loc) · 7.22 KB

ReadMe.md

File metadata and controls

54 lines (34 loc) · 7.22 KB

Kool Streams

Kool Streams is a simple framework for working with aynchronous events and collections. Kool Streams are inspired by a combination of the Reactive Extensions (Rx), Iteratees and various other similar approaches to dealing with concurrency.

Why Kool Stream?

Kool Streams provide a form of asynchronous collection or Event Stream that can be composed and processed like regular collections using the same kind of combinator API folks are familiar with (filter(), flatMap(), map(), fold() etc) but done asynchronously to deal with time delay, network communication, to use threads efficiently and avoid blocking.

API Overview

  • Stream represents a stream of asynchronous events. Its like an asynchronous collection, where events are pushed into a Handler rather than pulled via an iterator.
  • Handler is used to process the events from a stream, through you can just pass a function to handle each next event instead

A Stream is then opened via the open() method either passing in a handler in open(Handler) or by passing in a function to handle even next event via open(fn: (T) -> Unit).

When you open() a Stream you get back a Cursor which can be used to close the stream.

Stream contract

A Stream must only invoke a Handler from one thread at once; so a handler does not need to worry about being thread safe.

The lifecycle of events from a Handler perspective is a stream will invoke

This means that a Handler can choose to close a stream if it knows it has finished processing it. For example if you can use take(n) to limit the size of a stream.

Examples

Create event streams from various things:

Combine streams with Collection-style combinators

Using windows of events for complex event processing types of things

Finally you can pipe the events from a Stream to any Apache Camel Endpoint