Created
June 16, 2016 21:23
-
-
Save phausler/f6e6e6b3397f0ae004850761c4e57546 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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