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

https://github.com/h2337/eemit

Tiny event emitter library for Java
https://github.com/h2337/eemit

event-emitter eventbus eventemitter events java

Last synced: 2 months ago
JSON representation

Tiny event emitter library for Java

Awesome Lists containing this project

README

          

# eemit
eemit is a Java event emitter library. It lets you emit objects (from multiple places) of the specified type in a given channel and handle them elsewhere in code by subscribing to that channel.

### Install
Maven:
```xml

com.github.h2337
eemit
0.1.0

```

Gradle:
```groovy
implementation 'com.github.h2337:eemit:0.1.0'
```

### Usage
```java
import io.github.h2337.eemit.EventEmitter;

...

// Create EventEmitter with any type as an event type, here just String
EventEmitter emitter = new EventEmitter<>();

// Listen to events on channel "channel666", pass in a lambda that'll receive channel name and the event object
emitter.on("channel666", (channel, object) -> {
// Do something with object (which is String because we parameterized EventEmitter with String)
// "channel" argument will either be "channel666" or "*" here
});

// Listen to events on all channels
emitter.on("*", (channel, object) -> {
// Do something with object
});

// Emit an event on "channel666", second parameter is of type that you parameterized EventEmitter with
emitter.emit("channel666", "Some string");

// Emit to all channels
emitter.emit("*", "Some string");

// How to unlisten:
String uuid = emitter.on("channel666", (channel, object) -> {
// Do something with object
});
// Unregister callback
emitter.off(uuid);
```