Skip to content

Instantly share code, notes, and snippets.

@pietrocaselani
Created February 18, 2018 16:54
Show Gist options
  • Save pietrocaselani/394e7bff549913f90393d575d07e21c2 to your computer and use it in GitHub Desktop.
Save pietrocaselani/394e7bff549913f90393d575d07e21c2 to your computer and use it in GitHub Desktop.
RxSwift scheduler with run loop
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