Created
November 10, 2014 09:21
-
-
Save alexeckermann/ca984134d64910603ad3 to your computer and use it in GitHub Desktop.
GCD dispatch_resume test for Swift
This file contains 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
import Foundation | |
import XCPlayground | |
import Dispatch | |
class Looper { | |
var loopQueue : dispatch_queue_t! | |
var tickSource : dispatch_source_t! | |
init() { | |
loopQueue = dispatch_queue_create("com.alexeckermann.looper", nil) | |
println("looper initd") | |
} | |
func loop() { | |
println("loop called") | |
tickSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, loopQueue) | |
dispatch_source_set_timer(tickSource, dispatch_time(DISPATCH_TIME_NOW, 0), (200 * NSEC_PER_MSEC), (50 * NSEC_PER_MSEC)) | |
dispatch_source_set_event_handler(tickSource) { println("success!") } // Looking for this to print to the output | |
dispatch_async(loopQueue, { println("queue works") }) | |
dispatch_resume(tickSource) // Comment this out if it raises an exception/ | |
} | |
} | |
var looper = Looper() | |
looper.loop() | |
XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment