Skip to content

Instantly share code, notes, and snippets.

@acchou
Last active March 9, 2020 09:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save acchou/7b4806100c588e0681381cba5f1a8859 to your computer and use it in GitHub Desktop.
Save acchou/7b4806100c588e0681381cba5f1a8859 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