0001    //
0002    //  ImmediateScheduler.swift
0003    //  Rx
0004    //
0005    //  Created by Krunoslav Zaher on 10/17/15.
0006    //  Copyright © 2015 Krunoslav Zaher. All rights reserved.
0007    //
0008    
0009    import Foundation
0010    
0011    /**
0012    Represents an object that schedules units of work to run immediately on the current thread.
0013    */
0014    private class ImmediateScheduler : ImmediateSchedulerType {
0015    
0016        private let _asyncLock
ImmediateScheduler.swift:30
        _asyncLock.invoke(AnonymousInvocable {
= AsyncLock<AnonymousInvocable>() 0017 0018 /** 0019 Schedules an action to be executed immediatelly. 0020 0021 In case `schedule` is called recursively from inside of `action` callback, scheduled `action` will be enqueued 0022 and executed after current `action`. (`AsyncLock` behavior) 0023 0024 - parameter state: State passed to the action to be executed. 0025 - parameter action: Action to be executed. 0026 - returns: The disposable object used to cancel the scheduled action (best effort). 0027 */ 0028 func schedule<StateType>(state: StateType, action: (StateType) -> Disposable) -> Disposable { 0029 let disposable = SingleAssignmentDisposable() 0030 _asyncLock.invoke(AnonymousInvocable { 0031 if disposable.disposed { 0032 return 0033 } 0034 disposable.disposable = action(state) 0035 }) 0036 0037 return disposable 0038 } 0039 }