WebAsyncPreparePush Function

Action

Prepares an asynchronous communication channel for the push 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.

The callback will be called for each message part sent from the server and once with an empty sResponseBody argument when the communication channel is closed (end of response).

Include file

webapi.bdh

Syntax

WebAsyncPreparePush( 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

Returns a handle to the prepared asynchronous communication channel. This value has to be passed to WebAsyncStop() to stop the asynchronous communication and close the channel.

Example

dclfunc
  function FAsyncCallback(sResponseBody : string) <ASYNC_CALLBACK_FUNCTION>
  begin
    RepMessage("MESSAGE: '" + sResponseBody + "'", SEVERITY_INFORMATIONAL);
    if (StrSearch(sResponseBody, "last message", STR_SEARCH_FIRST) <> 0) then
      UserSignal("LastMessage");
    end;
  end FAsyncCallback;

dcltrans
  transaction TMainListen
  var
    nAsyncChannel : number;
  begin
    WebPageUrl("http://demo.borland.com:8080/atmosphere-meteor-pubsub-2.1.3/", "/atmosphere-meteor-pubsub-2.0.3/");
    nAsyncChannel := WebAsyncPreparePush(callback(FAsyncCallback));
    WebFormGet("http://demo.borland.com:8080/atmosphere-meteor-pubsub-2.1.3/pubsub/mychannel_1234", 
      METEOR_PUB_SUB_FORM);

    UserWaitFor("LastMessage", 60); 
    
    WebAsyncStop(nAsyncChannel);
    
  end TMainListen;