Add new pods.
- RxSwift - RXCocoa
This commit is contained in:
104
Pods/RxSwift/RxSwift/Concurrency/AsyncLock.swift
generated
Normal file
104
Pods/RxSwift/RxSwift/Concurrency/AsyncLock.swift
generated
Normal file
@ -0,0 +1,104 @@
|
||||
//
|
||||
// AsyncLock.swift
|
||||
// RxSwift
|
||||
//
|
||||
// Created by Krunoslav Zaher on 3/21/15.
|
||||
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/**
|
||||
In case nobody holds this lock, the work will be queued and executed immediately
|
||||
on thread that is requesting lock.
|
||||
|
||||
In case there is somebody currently holding that lock, action will be enqueued.
|
||||
When owned of the lock finishes with it's processing, it will also execute
|
||||
and pending work.
|
||||
|
||||
That means that enqueued work could possibly be executed later on a different thread.
|
||||
*/
|
||||
class AsyncLock<I: InvocableType>
|
||||
: Disposable
|
||||
, Lock
|
||||
, SynchronizedDisposeType {
|
||||
typealias Action = () -> Void
|
||||
|
||||
var _lock = SpinLock()
|
||||
|
||||
private var _queue: Queue<I> = Queue(capacity: 0)
|
||||
|
||||
private var _isExecuting: Bool = false
|
||||
private var _hasFaulted: Bool = false
|
||||
|
||||
// lock {
|
||||
func lock() {
|
||||
_lock.lock()
|
||||
}
|
||||
|
||||
func unlock() {
|
||||
_lock.unlock()
|
||||
}
|
||||
// }
|
||||
|
||||
private func enqueue(_ action: I) -> I? {
|
||||
_lock.lock(); defer { _lock.unlock() } // {
|
||||
if _hasFaulted {
|
||||
return nil
|
||||
}
|
||||
|
||||
if _isExecuting {
|
||||
_queue.enqueue(action)
|
||||
return nil
|
||||
}
|
||||
|
||||
_isExecuting = true
|
||||
|
||||
return action
|
||||
// }
|
||||
}
|
||||
|
||||
private func dequeue() -> I? {
|
||||
_lock.lock(); defer { _lock.unlock() } // {
|
||||
if _queue.count > 0 {
|
||||
return _queue.dequeue()
|
||||
}
|
||||
else {
|
||||
_isExecuting = false
|
||||
return nil
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
func invoke(_ action: I) {
|
||||
let firstEnqueuedAction = enqueue(action)
|
||||
|
||||
if let firstEnqueuedAction = firstEnqueuedAction {
|
||||
firstEnqueuedAction.invoke()
|
||||
}
|
||||
else {
|
||||
// action is enqueued, it's somebody else's concern now
|
||||
return
|
||||
}
|
||||
|
||||
while true {
|
||||
let nextAction = dequeue()
|
||||
|
||||
if let nextAction = nextAction {
|
||||
nextAction.invoke()
|
||||
}
|
||||
else {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func dispose() {
|
||||
synchronizedDispose()
|
||||
}
|
||||
|
||||
func _synchronized_dispose() {
|
||||
_queue = Queue(capacity: 0)
|
||||
_hasFaulted = true
|
||||
}
|
||||
}
|
38
Pods/RxSwift/RxSwift/Concurrency/Lock.swift
generated
Normal file
38
Pods/RxSwift/RxSwift/Concurrency/Lock.swift
generated
Normal file
@ -0,0 +1,38 @@
|
||||
//
|
||||
// Lock.swift
|
||||
// RxSwift
|
||||
//
|
||||
// Created by Krunoslav Zaher on 3/31/15.
|
||||
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol Lock {
|
||||
func lock()
|
||||
func unlock()
|
||||
}
|
||||
|
||||
// https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000321.html
|
||||
typealias SpinLock = NSRecursiveLock
|
||||
|
||||
extension NSRecursiveLock : Lock {
|
||||
@inline(__always)
|
||||
func performLocked(_ action: () -> Void) {
|
||||
lock(); defer { unlock() }
|
||||
action()
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
func calculateLocked<T>(_ action: () -> T) -> T {
|
||||
lock(); defer { unlock() }
|
||||
return action()
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
func calculateLockedOrFail<T>(_ action: () throws -> T) throws -> T {
|
||||
lock(); defer { unlock() }
|
||||
let result = try action()
|
||||
return result
|
||||
}
|
||||
}
|
23
Pods/RxSwift/RxSwift/Concurrency/LockOwnerType.swift
generated
Normal file
23
Pods/RxSwift/RxSwift/Concurrency/LockOwnerType.swift
generated
Normal file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// LockOwnerType.swift
|
||||
// RxSwift
|
||||
//
|
||||
// Created by Krunoslav Zaher on 10/25/15.
|
||||
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol LockOwnerType : class, Lock {
|
||||
var _lock: NSRecursiveLock { get }
|
||||
}
|
||||
|
||||
extension LockOwnerType {
|
||||
func lock() {
|
||||
_lock.lock()
|
||||
}
|
||||
|
||||
func unlock() {
|
||||
_lock.unlock()
|
||||
}
|
||||
}
|
20
Pods/RxSwift/RxSwift/Concurrency/SynchronizedDisposeType.swift
generated
Normal file
20
Pods/RxSwift/RxSwift/Concurrency/SynchronizedDisposeType.swift
generated
Normal file
@ -0,0 +1,20 @@
|
||||
//
|
||||
// SynchronizedDisposeType.swift
|
||||
// RxSwift
|
||||
//
|
||||
// Created by Krunoslav Zaher on 10/25/15.
|
||||
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol SynchronizedDisposeType : class, Disposable, Lock {
|
||||
func _synchronized_dispose()
|
||||
}
|
||||
|
||||
extension SynchronizedDisposeType {
|
||||
func synchronizedDispose() {
|
||||
lock(); defer { unlock() }
|
||||
_synchronized_dispose()
|
||||
}
|
||||
}
|
20
Pods/RxSwift/RxSwift/Concurrency/SynchronizedOnType.swift
generated
Normal file
20
Pods/RxSwift/RxSwift/Concurrency/SynchronizedOnType.swift
generated
Normal file
@ -0,0 +1,20 @@
|
||||
//
|
||||
// SynchronizedOnType.swift
|
||||
// RxSwift
|
||||
//
|
||||
// Created by Krunoslav Zaher on 10/25/15.
|
||||
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol SynchronizedOnType : class, ObserverType, Lock {
|
||||
func _synchronized_on(_ event: Event<E>)
|
||||
}
|
||||
|
||||
extension SynchronizedOnType {
|
||||
func synchronizedOn(_ event: Event<E>) {
|
||||
lock(); defer { unlock() }
|
||||
_synchronized_on(event)
|
||||
}
|
||||
}
|
20
Pods/RxSwift/RxSwift/Concurrency/SynchronizedSubscribeType.swift
generated
Normal file
20
Pods/RxSwift/RxSwift/Concurrency/SynchronizedSubscribeType.swift
generated
Normal file
@ -0,0 +1,20 @@
|
||||
//
|
||||
// SynchronizedSubscribeType.swift
|
||||
// RxSwift
|
||||
//
|
||||
// Created by Krunoslav Zaher on 10/25/15.
|
||||
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol SynchronizedSubscribeType : class, ObservableType, Lock {
|
||||
func _synchronized_subscribe<O: ObserverType>(_ observer: O) -> Disposable where O.E == E
|
||||
}
|
||||
|
||||
extension SynchronizedSubscribeType {
|
||||
func synchronizedSubscribe<O: ObserverType>(_ observer: O) -> Disposable where O.E == E {
|
||||
lock(); defer { unlock() }
|
||||
return _synchronized_subscribe(observer)
|
||||
}
|
||||
}
|
15
Pods/RxSwift/RxSwift/Concurrency/SynchronizedUnsubscribeType.swift
generated
Normal file
15
Pods/RxSwift/RxSwift/Concurrency/SynchronizedUnsubscribeType.swift
generated
Normal file
@ -0,0 +1,15 @@
|
||||
//
|
||||
// SynchronizedUnsubscribeType.swift
|
||||
// RxSwift
|
||||
//
|
||||
// Created by Krunoslav Zaher on 10/25/15.
|
||||
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol SynchronizedUnsubscribeType : class {
|
||||
associatedtype DisposeKey
|
||||
|
||||
func synchronizedUnsubscribe(_ disposeKey: DisposeKey)
|
||||
}
|
Reference in New Issue
Block a user