Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oSock
LOCAL oTask
LOCAL nCount
LOCAL s
LOCAL oConnection
LOCAL oAcceptedConnection

nSuccess := 0

//  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 (1/0), get returned value by calling GetResultBool.
//  For example..

oSock := CreateObject("Chilkat.Socket")

//  --------------------------------------------------------------
//  Synchronous call returning 1/0
nSuccess := oSock:Connect("example.com", 443, 1, 5000)

//  --------------------------------------------------------------
//  Asynchronous call
oTask := oSock:ConnectAsync("example.com", 443, 1, 5000)
//  ...
oTask:Run()
//  ...
//  ...
//  Get the status (1/0) value returned by the synchronous method called in the background thread.
nSuccess := oTask:GetResultBool()

//  --------------------------------------------------------------
//  Synchronous call returning an integer
nCount := oSock:ReceiveCount()

//  --------------------------------------------------------------
//  Asynchronous call
oTask := oSock:ReceiveCountAsync()
//  ...
oTask:Run()
//  ...
//  ...
//  Get the integer value returned by the synchronous method called in the background thread.
nCount := oTask:GetResultInt()

//  --------------------------------------------------------------
//  Synchronous call returning an string
s := oSock:ReceiveString()

//  --------------------------------------------------------------
//  Asynchronous call
oTask := oSock:ReceiveStringAsync()
//  ...
oTask:Run()
//  ...
//  ...
//  Get the string value returned by the synchronous method called in the background thread.
s := oTask:GetResultString()

//  --------------------------------------------------------------
//  Synchronous call returning an object
oConnection := oSock:AcceptNextConnection(5000)

//  --------------------------------------------------------------
//  Asynchronous call
oTask := oSock:AcceptNextConnectionAsync()
//  ...
oTask:Run()
//  ...
//  ...
//  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).
oAcceptedConnection := CreateObject("Chilkat.Socket")
IF (oTask:TaskSuccess == 1)
    nSuccess := oAcceptedConnection:LoadTaskResult(oTask)
ENDIF

oSock:destroy()
oAcceptedConnection:destroy()