Skip to content

Instantly share code, notes, and snippets.

@onmyway133
Created January 8, 2019 15:22
Show Gist options
  • Save onmyway133/a27f5871423c67aaf2505f3069122ea9 to your computer and use it in GitHub Desktop.
Save onmyway133/a27f5871423c67aaf2505f3069122ea9 to your computer and use it in GitHub Desktop.
a.swift
import Foundation
public final class Signal<T> {
var event: Event<T>?
var callbacks: [Event<T> -> Void] = []
let lockQueue = dispatch_queue_create("lock_queue", DISPATCH_QUEUE_SERIAL)
// MARK: Initialization
public init(event: Event<T>) {
self.event = event
}
public init(value: T) {
self.event = Event.Next(value: value)
}
public init() {
}
func notify() {
guard let event = event else {
return
}
callbacks.forEach { callback in
callback(event)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment