A lightweight, SwiftUI-style builder for chaining synchronous and asynchronous flow control steps in Swift.
- DSL-style syntax like SwiftUI
- Chain multiple actions in sequence
- Supports both synchronous and asynchronous tasks
- Conditional branching (
if
) - Built-in delay, log, and queue support
- Optional completion callback
- Clean and extensible design
pod 'SNFlowControl'
import SNFlowControl
func example1() {
SNFlowControl {
SNAction { context in
print("step1")
context(.onNext)
}
SNAction.log("record")
SNAction.then(onQueue: .none) {
print("do stuff")
}
SNAction.delay(onQueue: .main(createStyle: .none), seconds: 3)
SNAction.log("after delay 3 seconds")
SNAction.ifStop {
return true
}
SNAction { context in
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
context(.onNext)
}
}
SNAction.log("wait until async action finished")
} finished: {
print("flow control end")
}.start()
}
iOS 11.0+ macOS 10.13+ Swift 5.0+
MIT License. See LICENSE for details.
Inspired by functional reactive programming and SwiftUI DSL.