Async - in COBOL and Java

COBOL Java
*> Calling async methods
 invoke await type Task::Delay(1000)
 declare items = await ProcessItemsAsync("user", 8)

*> Run code on background thread
 await type Task::Run(
     delegate
         invoke type Console::WriteLine("On background thread")
     end-delegate)

*> An async void method
 method-id button1_Click async-void (sender as object,
                                     e as type EventArgs).
     set button1::Enabled to false
     invoke await type Task::Delay(1000)
     set button1::Enabled to true
 end method.
*> An async method returning no result
 method-id Task ProcessAsync() async.
     invoke await type Task::Yield()
     invoke type Console::WriteLine("async...")
 end method.
*> An async method returning a result
 method-id ProcessItemsAsync async (#type as string,
                                    #count as binary-long)
     yielding items as string occurs any.
     invoke await type Task::Delay(1000)
set items to table of ("a", "b", "c")
 end method.
*> An async value-task method returning a result
 method-id MaybeProcess async-value (x as condition-value)
                        yielding result as string.
     if x
         invoke await type Task::Delay(1000)
         set result to "x"
     else
         set result to "y"
     end-if
 end method.
// Java has no async coroutine support.
// Similar behaviour is typically achieved by using
// executors.

Portions of these examples were produced by Dr. Frank McCown, Harding University Computer Science Dept, and are licensed under a Creative Commons License.