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

https://github.com/minndevelopment/gunfire

Lightweight Event Bus for Kotlin
https://github.com/minndevelopment/gunfire

event event-emitter eventbus hierarchy kotlin lightweight

Last synced: 4 months ago
JSON representation

Lightweight Event Bus for Kotlin

Awesome Lists containing this project

README

          

# Project Gunfire

Project Gunfire is a lightweight event bus framework which is built in and for the Kotlin Programming Language.

This can be used to fire `bullets` with `guns`!

## Requirements

- Kotlin/JVM 1.1.1+ (including coroutines)
- Java Runtime for Java 8

### Dependencies

- Kotlinx-Coroutines for Kotlin 1.1.1+
- Kotlin std-jre8 1.1.1+

Recommended IDE: Intellij IDEA 2017.1

## Getting Started

To create an EventBus for your project you have to choose your **Gun**:

- Gun

The generic `Gun` which executes on the calling thread
- Sniper

Extension of a simple `Gun` which synchronizes each bullet shot
- Revolver

Extension of a simple `Gun` which can fire up to **6** bullets at once
- Uzi

Fully automatic `Gun` which uses kotlin coroutines for each bullet shot

Every Gun implementation inherits from the `Gun` class and iterates over all registered `targets`.

### Setup Target

```kotlin

import club.minnced.gunfire.core.Gun
import club.minnced.gunfire.core.impl.Sniper
import club.minnced.gunfire.core.target

val gun: Gun = Sniper()

fun main(args: Array) {
gun.target {
it.error.printStackTrace()
}
gun.target {
println(it.message)
}
}
```

> Note: Here we register a target that will print every **Throwable** that is caught by the Gun!

> Using the `Backfire` bullet specification!

### Fire Gun

```kotlin
import club.minnced.gunfire.core.Gun
import club.minnced.gunfire.core.impl.Sniper
import club.minnced.gunfire.core.fire

class LogBullet(val message: String)

fun logMessage(message: String) {
gun.fire {
LogBullet(message)
}
}
```

> Note: Here we fire a LogBullet which holds a message for the targets!

## Setup

JitPack Version: [ ![version](https://jitpack.io/v/MinnDevelopment/Gunfire.svg) ](https://jitpack.io/#MinnDevelopment/Gunfire)

### Gradle

```gradle
respositories {
jcenter()
maven {
name 'jitpack.io'
url 'https://jitpack.io'
}
// ...
}

dependencies {
compile 'org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1'
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.14'
compile 'com.github.MinnDevelopment.Gunfire:core:master-SNAPSHOT'
compile 'com.github.MinnDevelopment.Gunfire:commons:master-SNAPSHOT'
// ...
}
```

### Maven

```xml

https://jitpack.io


com.github.MinnDevelopment.Gunfire
core
master-SNAPSHOT


com.github.MinnDevelopment.Gunfire
commons
master-SNAPSHOT

```

## Examples

There is a [Step-by-Step](https://github.com/MinnDevelopment/Gunfire/tree/master/Examples/Step%20by%20Step/src/main/kotlin) guide
and an example which uses bullets to print messages to the console in the [Examples Directories](https://github.com/MinnDevelopment/Gunfire/tree/master/Examples)!