Skip to content

Instantly share code, notes, and snippets.

@phausler
Created June 16, 2016 21:23
Show Gist options
  • Save phausler/f6e6e6b3397f0ae004850761c4e57546 to your computer and use it in GitHub Desktop.
Save phausler/f6e6e6b3397f0ae004850761c4e57546 to your computer and use it in GitHub Desktop.
import Foundation
class ConsumerOperation<T> : Operation {
private var consumer: (T) -> Void
private weak var prodcuer: ProducerOperation<T>?
init(prodcuer: ProducerOperation<T>, consumer: (T) -> Void) {
self.prodcuer = prodcuer
self.consumer = consumer
super.init()
}
override func main() {
if let res = prodcuer?.result {
consumer(res)
}
}
}
class ProducerOperation<T> : Operation {
var result: T?
var producer: () -> T
init(producer: () -> T) {
self.producer = producer
super.init()
}
override func main() {
result = producer()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment