https://github.com/notjustanna/eventpipes
Event Pipes for Java. Quite Reactive.
https://github.com/notjustanna/eventpipes
java
Last synced: about 1 month ago
JSON representation
Event Pipes for Java. Quite Reactive.
- Host: GitHub
- URL: https://github.com/notjustanna/eventpipes
- Owner: NotJustAnna
- License: mit
- Created: 2019-02-14T18:00:50.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-26T14:09:04.000Z (over 6 years ago)
- Last Synced: 2025-01-02T03:46:18.742Z (over 1 year ago)
- Topics: java
- Language: Java
- Size: 73.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EventPipes
Fully configured lightweight event publishing/subscribing library, made in pure Java.
The library is REALLY small and is made on pure Java 8.
Licensed under the [MIT License](https://github.com/arudiscord/eventpipes/blob/master/LICENSE).
### Installation

Using in Gradle:
```gradle
repositories {
jcenter()
}
dependencies {
compile 'pw.aru.libs:eventpipes:LATEST' // replace LATEST with the version above
}
```
Using in Maven:
```xml
central
bintray
http://jcenter.bintray.com
pw.aru.libs
eventpipes
LATEST
```
### Usage
The starting point of the library is the `EventPipes` class.
- Use `EventPipes.newPipe` (or `newAsyncPipe`) to create your first pipe.
- If you need stuff being handled by the key, use `EventPipes.newKeyedPipe` (or `newAsyncKeyedPipe`)
- `EventPipe` implements `EventPublisher` and `EventSubscriber`, and the actual `publish`/`subscribe` methods are on that class.
### Example Implementations:
```java
public interface MyEvents {
EventPipe READY = newAsyncPipe();
EventPipe EVERY_SECOND = newAsyncPipe();
EventPipe REDIS_MESSAGES = newAsyncPipe();
}
public class EventEmitter extends MyEvents {
public static void emitEvents() throws Exception {
READY.publish(new ReadyEvent());
for(int i = 0; i < 100; i++) {
EVERY_SECOND.publish(i);
Thread.sleep(1000);
}
MyRedis.instance().subscribe("very-important-messages", REDIS_MESSAGES::publish);
}
}
public class MyEventAPI {
public final EventSubscriber onReady;
public final EventSubscriber eachSecond;
public MyEventAPI() {
EventPipe readyPipe = newAsyncPipe();
EventPipe secondPipe = newAsyncPipe();
onReady = readyPipe.subscriber();
eachSecond = secondPipe.subscriber();
MyEventGateway gateway = new GatewayImpl(this, readyPipe.publisher(), eachSecond.publisher());
gateway.connect("https://my-gateway.what-a-cool-discord-bot.com/v6/");
}
}
```
### Support
Support is given on [Aru's Discord Server](https://discord.gg/URPghxg)
[](https://discord.gg/URPghxg)