Sample code for 30+ languages & platforms
DataFlex

Understanding Async Function Return Values

See more Async Examples

Explains how to get the return value of the function called synchonously in the background thread.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoSock
    Variant vTask
    Handle hoTask
    Integer iCount
    String s
    Variant vConnection
    Handle hoConnection
    Handle hoAcceptedConnection
    Boolean bTemp1

    Move False To iSuccess

    // Some Chilkat functions can be called asynchronously.
    // If a function "Func" can be called asynchronously, there will be a corresponding "FuncAsync" function that returns a Task object.
    // 
    // When Task.Run is called, the synchronous "Func" runs in a background thread.
    // 

    // For Chilkat methods that return a status (True/False), get returned value by calling GetResultBool.
    // For example..

    Get Create (RefClass(cComChilkatSocket)) To hoSock
    If (Not(IsComObjectCreated(hoSock))) Begin
        Send CreateComObject of hoSock
    End

    // --------------------------------------------------------------
    // Synchronous call returning True/False
    Get ComConnect Of hoSock "example.com" 443 True 5000 To iSuccess

    // --------------------------------------------------------------
    // Asynchronous call
    Get ComConnectAsync Of hoSock "example.com" 443 True 5000 To vTask
    If (IsComObject(vTask)) Begin
        Get Create (RefClass(cComChilkatTask)) To hoTask
        Set pvComObject Of hoTask To vTask
    End
    // ...
    Get ComRun Of hoTask To iSuccess
    // ...
    // ...
    // Get the status (True/False) value returned by the synchronous method called in the background thread.
    Get ComGetResultBool Of hoTask To iSuccess

    // --------------------------------------------------------------
    // Synchronous call returning an integer
    Get ComReceiveCount Of hoSock To iCount

    // --------------------------------------------------------------
    // Asynchronous call
    Get ComReceiveCountAsync Of hoSock To vTask
    If (IsComObject(vTask)) Begin
        Get Create (RefClass(cComChilkatTask)) To hoTask
        Set pvComObject Of hoTask To vTask
    End
    // ...
    Get ComRun Of hoTask To iSuccess
    // ...
    // ...
    // Get the integer value returned by the synchronous method called in the background thread.
    Get ComGetResultInt Of hoTask To iCount

    // --------------------------------------------------------------
    // Synchronous call returning an string
    Get ComReceiveString Of hoSock To s

    // --------------------------------------------------------------
    // Asynchronous call
    Get ComReceiveStringAsync Of hoSock To vTask
    If (IsComObject(vTask)) Begin
        Get Create (RefClass(cComChilkatTask)) To hoTask
        Set pvComObject Of hoTask To vTask
    End
    // ...
    Get ComRun Of hoTask To iSuccess
    // ...
    // ...
    // Get the string value returned by the synchronous method called in the background thread.
    Get ComGetResultString Of hoTask To s

    // --------------------------------------------------------------
    // Synchronous call returning an object
    Get ComAcceptNextConnection Of hoSock 5000 To vConnection
    If (IsComObject(vConnection)) Begin
        Get Create (RefClass(cComChilkatSocket)) To hoConnection
        Set pvComObject Of hoConnection To vConnection
    End

    // --------------------------------------------------------------
    // Asynchronous call
    Get ComAcceptNextConnectionAsync Of hoSock To vTask
    If (IsComObject(vTask)) Begin
        Get Create (RefClass(cComChilkatTask)) To hoTask
        Set pvComObject Of hoTask To vTask
    End
    // ...
    Get ComRun Of hoTask To iSuccess
    // ...
    // ...
    // Get the object returned by the synchronous method called in the background thread.
    // We do this a little differently.  We create an new object of the same type,
    // and then load it with the returned object (assuming it was not null).
    Get Create (RefClass(cComChilkatSocket)) To hoAcceptedConnection
    If (Not(IsComObjectCreated(hoAcceptedConnection))) Begin
        Send CreateComObject of hoAcceptedConnection
    End
    Get ComTaskSuccess Of hoTask To bTemp1
    If (bTemp1 = True) Begin
        Get ComLoadTaskResult Of hoAcceptedConnection vTask To iSuccess
    End



End_Procedure