antonvmironov on master
Initial implementation of conve… (compare)
antonvmironov on master
Fix bindings memory issue where… (compare)
antonvmironov on master
Reimplementing NSControl reacti… (compare)
antonvmironov on master
Debugging assistance added Extracting reactive testing ext… Making test fixtures shared acr… and 1 more (compare)
antonvmironov on master
Fixing swift version for cocoap… (compare)
antonvmironov on 1.3.2
Fixing swift version for cocoap… (compare)
_asyncNinja_notifyFinalization
does.
func merge<Update,Success>(channels: [Channel<Update,Success>]) -> Channel<Update,Void> {
return channel(executor: Executor.primary) { (producer : Producer<Update,Void>) -> Void in
for ch in channels {
ch.bind(producer)
}
}
}
let selection = merge(channels: myView.checkboxes.map { $0.actionChannel() } )
.debounce(interval: 1)
func download(from: String, to: String) -> Channel<Double,URL>
func unzip(from: String, to: String, password: String) -> Channel<Double,URL>
func prepareSourceFiles() -> Channel<Double,URL> {
return download(from: webURL, to: dstZip)
.map { $0 / 2.0 } // 100% is 50% <= IGNORED
.flatMapSuccess { unzip(from: $0.path, to: dstUnzip, password: "qwerty") }
.map { 0.5 + $0 / 2.0 } // 0% is 50%
}
import Foundation
typealias ES = EventSource
func combineLatestUpdates<ES1:ES, ES2:ES>(_ es1: ES1, _ es2: ES2, executor: Executor = Executor.main)
-> Channel<(ES1.Update,ES2.Update),(ES1.Success, ES2.Success)> {
return CombineLatest2(es1, es2, executor: executor).producer
}
fileprivate class CombineLatest2<ES1:ES, ES2:ES> : ExecutionContext, ReleasePoolOwner {
typealias ResultUpdate = (ES1.Update, ES2.Update)
typealias ResultSuccess = (ES1.Success, ES2.Success)
public let releasePool = ReleasePool()
public var executor: Executor
var update1 : ES1.Update?
var update2 : ES2.Update?
var success1 : ES1.Success?
var success2 : ES2.Success?
let producer = Producer<ResultUpdate,ResultSuccess>()
init(_ es1: ES1, _ es2: ES2, executor: Executor) {
self.executor = executor
producer._asyncNinja_retainUntilFinalization(self)
es1.onUpdate(context: self) { ctx, upd in ctx.update1 = upd; ctx.trySendUpdate() }
.onSuccess(context: self) { ctx, success in ctx.success1 = success; ctx.tryComplete() }
.onFailure(context: self) { ctx, error in ctx.producer.fail(error) }
es2.onUpdate(context: self) { ctx, upd in ctx.update2 = upd; ctx.trySendUpdate() }
.onSuccess(context: self) { ctx, success in ctx.success2 = success; ctx.tryComplete() }
.onFailure(context: self) { ctx, error in ctx.producer.fail(error) }
}
func trySendUpdate() {
guard let upd1 = update1 else { return }
guard let upd2 = update2 else { return }
producer.update((upd1,upd2))
}
func tryComplete() {
guard let suc1 = success1 else { return }
guard let suc2 = success2 else { return }
producer.succeed((suc1,suc2), from: executor)
}
}
producer._asyncNinja_retainUntilFinalization(self)
extension Retainer {
func combineLatestUpdates<ES1:ES, ES2:ES>(_ es1: ES1, _ es2: ES2, executor: Executor = Executor.main)
-> Channel<(ES1.Update,ES2.Update),(ES1.Success, ES2.Success)> {
return CombineLatest2(es1, es2, executor: executor)
.retain(with: self)
.producer
}
}