WebAsyncPrepareLongPoll Function

Action

Prepares an asynchronous communication channel for the long poll model. The next BDL API call must be a low-level web API call, which will initiate an asynchronous communication channel. Asynchronous page-level API calls are not supported. The asynchronous request(s) happen in the background and will be executed in parallel to subsequent BDL API calls in the script.

An asynchronous communication channel is closed either by calling the BDL function WebAsyncStop() or when the browser session ends or at the end of the transaction if first time user behaviour is configured.

Long poll requests are performed automatically until the asynchronous communication channel is closed. One long poll request follows immediately after the other. The callback will be called for each response message part received from the server and with an empty sResponseBody argument once the communication channel is closed.

Include file

webapi.bdh

Syntax

WebAsyncPrepareLongPoll( in cbResponseCallback : callback optional ): number;
Parameter Description
cbResponseCallback The asynchronous response callback function. It has to be passed with the callback keyword (for example: callback(FCallback). The function has to be declared as follows:

function FWebAsyncResponseCallback(sResponseBody : string) <ASYNC_CALLBACK_FUNCTION>.

The function has to be of type ASYNC_CALLBACK_FUNCTION. sResponseBody of the callback contains the content of the current response message part.

Return value

  • true if successful

  • false otherwise

Example

var 
  nTrackingId : number;
dclfunc
  function FAsyncCallback(sResponseBody : string) <ASYNC_CALLBACK_FUNCTION>
  begin
    if Strlen(sResponseBody) = 0 then return end;
    
    RepMessage("MESSAGE: '" + sResponseBody + "'", SEVERITY_INFORMATIONAL);
   
    if (nTrackingId >= 5) then 
      UserSignal("LastMessage");
    else
      nTrackingId := nTrackingId+1;
    end;
  end FAsyncCallback;

dcltrans
  transaction TMain
  var
    nAsyncChannel : number;
  begin
    nTrackingId := 0;

    nAsyncChannel := WebAsyncPrepareLongPoll(callback(FAsyncCallback));
    WebFormGet("http://lnz-testsite/showImage.php", FORM_PARAMS);

    UserWaitFor("LastMessage", 60); 

    WebAsyncStop(nAsyncChannel);
  end TMain;
  

dclform
  
  FORM_PARAMS:
    "timewait"   := 1,
    "id="        := nTrackingId;