-
Notifications
You must be signed in to change notification settings - Fork 191
Dispatch Module
In order to have full access Grand Central Dispatch (GCD) APIs, MacRuby has the module and some classes.
- Dispatch Module
- Dispatch::Queue Class
- Dispatch::Group Class
- Dispatch::Source Class
- Dispatch::Semaphore Class
Indicates a time that occurs immediately. This constant is defined in GCD API as DISPATCH_TIME_NOW
.
gcdq = Dispatch::Queue.new('sample')
gcdq.after(Dispatch::TIME_NOW) { puts "Hello" }
sleep 0.5
Indicates a time that means infinity.
This constant is defined in GCD API as DISPATCH_TIME_FOREVER
.
gcdq = Dispatch::Queue.new('sample')
sema = Dispatch::Semaphore.new(0)
gcdq.async {
puts "Hello, "
sleep 1
sema.signal
}
puts "Waiting..."
sema.wait(Dispatch::TIME_FOREVER)
puts "World"
Resume the invocation of suspended dispatch queue or dispatch event source objects on a dispatch object.
This method is declared in GCD API as dispatch_resume
.
- resume!
gcdq = Dispatch::Queue.new('sample')
gcdq.after(Dispatch::TIME_NOW) {
sleep 0.5
puts "Hello"
}
gcdq.suspend!
gcdq.suspended? #=> true
gcdq.resume!
sleep 1
Suspends the invocation of dispatch queue or dispatch event source objects on a dispatch object.
This method is declared in GCD API as dispatch_suspend
.
- suspend!
Returns whether the invocation is suspended.
- suspended? -> bool
- [RETURN]
- Returns a
true
if suspended, otherwisefalse
.
- Returns a
- [RETURN]
Returns the object of dispatch_object_t type for passing into Cocoa APIs which need the object of dispatch_queue_t type and etc.
- dispatch_object -> object
- [RETURN]
- Returns a dispatch object
- [RETURN]
gcdq = Dispatch::Queue.new('doc')
output = AVCaptureVideoDataOutput.new
output.setSampleBufferDelegate(self, queue: gcdq.dispatch_object)