Created
February 18, 2018 16:54
-
-
Save pietrocaselani/394e7bff549913f90393d575d07e21c2 to your computer and use it in GitHub Desktop.
RxSwift scheduler with run loop
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
final class ThreadWithRunLoopScheduler: ImmediateSchedulerType { | |
private let thread: ThreadWithRunLoop | |
init(name: String) { | |
thread = ThreadWithRunLoop() | |
thread.name = name | |
thread.start() | |
} | |
func schedule<StateType>(_ state: StateType, action: @escaping (StateType) -> Disposable) -> Disposable { | |
let disposable = SingleAssignmentDisposable() | |
thread.runLoop.perform { | |
disposable.setDisposable(action(state)) | |
} | |
return disposable | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment