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
- Host: GitHub
- URL: https://github.com/h2337/eemit
- Owner: h2337
- License: mit
- Created: 2020-06-23T14:17:03.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-07-19T17:05:10.000Z (3 months ago)
- Last Synced: 2025-08-04T08:58:44.210Z (3 months ago)
- Topics: event-emitter, eventbus, eventemitter, events, java
- Language: Java
- Homepage:
- Size: 59.6 KB
- Stars: 23
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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:
```xmlcom.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);
```