Skip to content


Subversion checkout URL

You can clone with
Download ZIP

Dispatch::Group Class

Watson1978 edited this page · 2 revisions

You could use the group to synchronize the dispatch queues which invoked for asynchronous.

Methods in Dispatch::Group class

Creates a new group with which block objects can be associated.

  • new -> Group
    • [RETURN]
      • Returns a new group instance


Schedules a block object to be submitted to a queue when a group of previously submitted block objects have completed. This method is declared in GCD API as dispatch_group_notify.

  • notify(queue) { ... }
    • [PARAM] queue:
      • Specify a queue to which the supplied block is submitted when the group completes.
gcdq ='sample')
gcdg =
@i = 0
gcdq.async { @i = 42 }
gcdg.notify(gcdq) { p @i } # => 42


This method is alias of Dispatch::Group#notify


Waits synchronously for the previously submitted block objects to complete. This method is declared in GCD API as dispatch_group_wait.

  • wait(timeout = Dispatch::TIME_FOREVER) -> bool
    • [PARAM] timeout:
      • Specify a value of timeout if needed. The default value is Dispatch::TIME_FOREVER.
    • [RETURN]
      • Returns a true if all completed, false if timed out.
gcdq ='sample')
gcdg =
gcdq.async(gcdg) { sleep 5 }
gcdg.wait # => true

gcdq.async(gcdg) { sleep 5 }
gcdg.wait(1) # => false
Something went wrong with that request. Please try again.