Skip to content

Commit

Permalink
Merge pull request #3 from ChaosCoder/easierTesting
Browse files Browse the repository at this point in the history
Easier testing
  • Loading branch information
ChaosCoder authored Jan 11, 2021
2 parents 617d875 + fa9df17 commit d607567
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Shouter.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Shouter"
s.version = "0.4.1"
s.version = "0.5.0"
s.summary = "A type safe, thread safe and memory safe alternative for NotificationCenter"
s.homepage = "https://github.com/ChaosCoder/Shouter"
s.license = { :type => 'MIT', :file => 'LICENSE.md' }
Expand Down
15 changes: 13 additions & 2 deletions Sources/Shouter/Shouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@

import Foundation

public class Shouter {
public protocol ShouterType {
func register<T>(_ type: T.Type, observer: T)
func unregister<T>(_ type: T.Type, observer: T)
func unregister<T>(_ type: T.Type)
func notify<T>(_ type: T.Type, block: (T) -> Void)
}

public class Shouter: ShouterType {

public static let `default` = Shouter()

fileprivate typealias Key = String
fileprivate var observers: [Key: NSHashTable<AnyObject>] = [:]
fileprivate let notificationQueue = DispatchQueue(label: "com.swift.notification.center.dispatch.queue", attributes: .concurrent)
fileprivate let notificationQueue: DispatchQueue

public init(notificationQueue: DispatchQueue = DispatchQueue(label: "de.chaosspace.Shouter.dispatch.queue", attributes: .concurrent)) {
self.notificationQueue = notificationQueue
}

public func register<T>(_ type: T.Type, observer: T) {
notificationQueue.sync(flags: .barrier) {
Expand Down

0 comments on commit d607567

Please sign in to comment.