How to set event-procedure in asynchronous calls

Posted by Kai Siegele on 09-Feb-2017 08:28

Hallo,

I want to invoke a procedure using an asynchronous request as described in knowledgebase.progress.com/.../20785.

For that purpose:
* I have written a very simple procedure AddTwoValues running on the application server getting two integer-values as input parameter and returning the sum as output parameter.

* I have defined the following callback procedure

PROCEDURE OnAddTwoValuesExecuted:
 
    DEFINE INPUT PARAMETER sumResult AS INTEGER NO-UNDO.

    RUN ShowResult("asynchron", sumResult).

END PROCEDURE.

* I have written the following code to invoke the procedure on application server (the Show... procedures writes infos in an output-file):

PROCEDURE AddTwoValuesAsynchronous:

    DEFINE INPUT PARAMETER hAppServer AS HANDLE NO-UNDO.
    DEFINE INPUT PARAMETER fv AS INTEGER NO-UNDO.
    DEFINE INPUT PARAMETER sv AS INTEGER NO-UNDO.

    DEFINE VARIABLE way AS CHARACTER INITIAL "asynchron" NO-UNDO.
    DEFINE VARIABLE sumfsv AS INTEGER NO-UNDO.
    DEFINE VARIABLE hProcess AS HANDLE NO-UNDO.
   
    RUN ShowInvoke("AddTwoValues", way, fv, sv).
    RUN Tests/AddTwoValues.p
        ASYNCHRONOUS SET hProcess EVENT-PROCEDURE "OnAddTwoValuesExecuted"              
        ON SERVER hAppServer(INPUT fv, INPUT sv, OUTPUT sumfsv).

END PROCEDURE.

Unfortunately the callback procedure is never called. Has anyone an idea  why? Calculating the result with a synchronous call like RUN Tests/AddTwoValues.p ON SERVER hAppServer(INPUT fv, INPUT sv, OUTPUT sumfsv). works without problems.

Kind regards
Kai Siegele

Posted by Fernando Souza on 09-Feb-2017 09:08

Did you also copy the code that is checking if the request is complete and calling PROCESS EVENTS? Or do you have some wait-for in effect ?

When the response from the asynchronous request is received (that is, a PROCEDURE-COMPLETE event occurs), the specified internal procedure is called during subsequent execution of a PROCESS EVENTS or input-blocking statement (such as WAIT-FOR).

Normally in a GUI application, you will have some wait-for in effect when you have a window running, so that should be sufficient. But if you are running this in a .p just for testing purposes, you need to make sure you have some input-blocking statement.  You can have this right after the RUN Tests/AddTwoValues.p call:

WAIT-FOR PROCEDURE-COMPLETE OF hProcess .

This will cause the code to wait until the response from the asynchronous request is received and then it will cause the callback to be executed.

Also, you have to make sure that the procedure where the callback is defined is still in scope until the event is processed. That is, if you are running this in a single .p non-persistently, you can't return from the .p until the response from the request is processed, or we won't be able to find the callback procedure.

All Replies

Posted by Fernando Souza on 09-Feb-2017 09:08

Did you also copy the code that is checking if the request is complete and calling PROCESS EVENTS? Or do you have some wait-for in effect ?

When the response from the asynchronous request is received (that is, a PROCEDURE-COMPLETE event occurs), the specified internal procedure is called during subsequent execution of a PROCESS EVENTS or input-blocking statement (such as WAIT-FOR).

Normally in a GUI application, you will have some wait-for in effect when you have a window running, so that should be sufficient. But if you are running this in a .p just for testing purposes, you need to make sure you have some input-blocking statement.  You can have this right after the RUN Tests/AddTwoValues.p call:

WAIT-FOR PROCEDURE-COMPLETE OF hProcess .

This will cause the code to wait until the response from the asynchronous request is received and then it will cause the callback to be executed.

Also, you have to make sure that the procedure where the callback is defined is still in scope until the event is processed. That is, if you are running this in a single .p non-persistently, you can't return from the .p until the response from the request is processed, or we won't be able to find the callback procedure.

Posted by Kai Siegele on 10-Feb-2017 01:50

Hallo Fernando,

thanks for your mail.

You guessed right. I have copied the code starting with DO WHILE NOT hServer:COMPLETE to check wehther all requests sent to application server have been processed. Unfortunately this code does not work and I created another post.

Kind regards

Kai Siegele

This thread is closed