Skip to content

Instantly share code, notes, and snippets.

@romyilano
Forked from acchou/SupportCode.swift
Created January 23, 2018 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romyilano/3c9ce997e2c89ad8f0ef93c479a6f1c5 to your computer and use it in GitHub Desktop.
Save romyilano/3c9ce997e2c89ad8f0ef93c479a6f1c5 to your computer and use it in GitHub Desktop.
Playground support code for using RxSwift or any other framework that sends async events.
import Foundation
public func delay(_ delay: TimeInterval, closure: @escaping ()->()) {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
closure()
}
}
#if NOT_IN_PLAYGROUND
public func playgroundTimeLimit(seconds: TimeInterval) {
}
#else
import PlaygroundSupport
public func playgroundTimeLimit(seconds: TimeInterval) {
PlaygroundPage.current.needsIndefiniteExecution = true
delay(seconds) {
PlaygroundPage.current.finishExecution()
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment