Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zeroflag/java8-announcer

A simple Smalltalk Announcers like library for Java 8
https://github.com/zeroflag/java8-announcer

Last synced: 15 days ago
JSON representation

A simple Smalltalk Announcers like library for Java 8

Awesome Lists containing this project

README

        

[![Build Status](https://travis-ci.org/zeroflag/java8-announcer.svg?branch=master)](https://travis-ci.org/zeroflag/java8-announcer)

```java
Announcer announcer = new Announcer();

// simple lambda subscriptions
announcer.subscribe(String.class, str -> System.out.println("received string: " + str));
announcer.subscribe(Number.class, n -> System.out.println("received number: " + n));
announcer.subscribe(Integer.class, i -> System.out.println(i*2));

// announce events
announcer.announce("test string");
announcer.announce(3);

// custom listener and event objects
MyListener listener = new MyListener();
announcer.subscribe(AnEvent.class, listener::onTestEvent);
announcer.announce(new AnEvent("some payload"));
announcer.announce(new ASubEvent("some payload"));

// unsubscribe
Subscription subscription = announcer.subscribe(AnEvent.class, (evt) -> {})
announcer.unsubscribe(subscription);
```