Module async

Provides the capability to write sequential code that works asynchronously.

For the specifics how the type of usage this emulates, see C# async

Functions

async (f) Alters the given function to work asynchronously.


Functions

async (f)
Alters the given function to work asynchronously.

Remarks:

    When f is called altered using this function, it can call functions await, resp. awaitFunction to postpone itself until a promise is fulfilled, resp. a callback is called.

Parameters:

  • f func Function that should be altered.

Returns:

    func The altered function that can be called. The function itself then doesn't return its return values normally, but in a form of a Promise.

Usage:

     myFunction = async(function(a)
       local result = awaitFunction(Dialog.showDialog, { message = a, ... })
       return result and true or false
     end)
    
     myOtherFunction = async(function())
       Spring.Echo("Before")
       if(await(myFunction("Hello")))then
         Spring.Echo("Hello.")
       end
       if(await(myFunction("Goodbye")))then
         Spring.Echo("After Goodbye.")
       end
     end)
generated by LDoc 1.4.3 Last updated 2017-06-01 23:07:48