https://github.com/trendyol/boru
Boru is a pipeline solution
https://github.com/trendyol/boru
courotines kotlin pipeline
Last synced: 7 months ago
JSON representation
Boru is a pipeline solution
- Host: GitHub
- URL: https://github.com/trendyol/boru
- Owner: Trendyol
- License: mit
- Created: 2021-09-14T11:56:25.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-02-03T11:19:52.000Z (11 months ago)
- Last Synced: 2025-03-22T05:33:00.181Z (10 months ago)
- Topics: courotines, kotlin, pipeline
- Language: Kotlin
- Homepage:
- Size: 114 KB
- Stars: 39
- Watchers: 10
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# boru [](https://maven-badges.herokuapp.com/maven-central/com.trendyol/boru)  [](https://codecov.io/gh/Trendyol/boru)

boru is a pipeline implementation in kotlin with native coroutine support and custom dsl.
Supports chaining pipeline steps with conditions and branches.
Inspired by [@oguzhaneren](https://github.com/oguzhaneren)'s C# implementation
```
com.trendyol
boru
1.0.0
```
## USAGE
#### Defining Context
Define a context implementing PipelineContext. In this case a simple context that sets and gets a text field
```kotlin
interface PipelineContext {
val items: Map
}
class TestDataContext : PipelineContext {
override val items: MutableMap = mutableMapOf()
var intValue: Int = 0
var text: String?
get() = items.getOrDefault("Text", null).toString()
set(value) {
items["Text"] = value!!
}
}
```
#### Define Pipeline Steps
Implement a pipeline step using TestDataContext
```kotlin
class TestWriterStep(
private val text: String,
) : PipelineStep {
override suspend fun execute(context: TestDataContext, next: PipelineStepDelegate) {
context.text = text
next(context)
}
}
```
#### Build Pipeline
```kotlin
fun compose() {
val pipeline = PipelineBuilder()
.usePipelineStep(TestWriterStep("hello"))
.build()
val context = TestDataContext()
}
```
You can also use lambda functions without defining a pipeline step
```kotlin
fun compose() {
val pipeline = PipelineBuilder()
.use { context: TestDataContext, next: suspend () -> Unit ->
context.text = "hello"
next()
}
.build()
val context = TestDataContext()
}
```
Or use built-in dsl
```kotlin
fun compose() {
val pipeline = pipelineBuilder {
use { testDataContext: TestDataContext, next: suspend () -> Unit ->
context.text = "Hello World"
next()
}
}
}
```
#### Conditions and Branching
You can also use conditions when executing steps or branch using map operation
```kotlin
fun compose() {
val pipeline = pipelineBuilder {
usePipelineStepWhen(TestWriterStep("Hello World")) {
it.text == "ExecuteStep"
}
}
}
```
Mapping allows you to group multiple steps under one condition.
```kotlin
fun composeMapping() {
val pipeline = pipelineBuilder {
map({ it.intValue < 3 }) {
usePipelineStep(TestWriterStep("one"))
usePipelineStep(TestWriterStep("two"))
}
map({ it.intValue == 3 }) {
usePipelineStep(TestWriterStep("three"))
}
}
}
```
## Examples
You can check out other [examples](/examples)