Created
January 8, 2019 15:22
-
-
Save onmyway133/a27f5871423c67aaf2505f3069122ea9 to your computer and use it in GitHub Desktop.
a.swift
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 | |
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