FutureBasic Logo

<<    Index    >> FutureBasic

dispatchasync   statement



Syntax
dispatchasync labelOrQueue [, wait [, release ] ]
// code
dispatchend

Description
Submits a block of code for asynchronous or synchronous execution on a specified dispatch queue.

Parameters
Parameter
Description
labelOrQueue Either a CFString literal (queue label) or an existing dispatch_queue_t object.
wait Optional BOOL. If YES, the block runs synchronously (waits for completion). Default: NO.
release Optional BOOL. Whether to release the queue after execution. Default: YES for labels, NO for queues.
 

Examples - Label Form (creates a new queue internally)

1. Default (asyncronous, autoreleasing)

dispatchasync @"com.example.queue1"
// user code
dispatchend
 

2. Synchronous execution (wait = YES)

dispatchasync @"com.example.queue1", YES
// user code
dispatchend

Examples - Queue Form (uses an existing queue)

1. Default (asyncronous, no release). Note: Developer takes responsibility for queue lifetime.

dispatch_queue_t queue1 = fn dispatch_queue_create( fn StringUTF8String( @"com.example.queue1" ), NULL )
dispatchasync queue1
// user code
dispatchend
 

2. Synchronous execution (wait = YES, no release). Note: Developer takes responsibility for queue lifetime.

dispatch_queue_t queue1 = fn dispatch_queue_create( fn StringUTF8String( @"com.example.queue1" ), NULL )
dispatchasync queue1, YES
// user code
dispatchend
 

3. Asyncronous, autoeleasing.

dispatch_queue_t queue1 = fn dispatch_queue_create( fn StringUTF8String( @"com.example.queue1" ), NULL )
dispatchasync queue1,, YES
// user code
dispatchend

See also
dispatchmain; dispatchglobal; dispatchend; dispatchapply
 
Apple documentation
Dispatch