How do I implement ASYNC?

I have been looking at implementing [async] in the cdef file as shown here:
https://legato.io/legato-docs/latest/defFilesCdef.html

Legato 16.10.4
Mangoh green WP85 firmware Rev 15

I have a client and a server, both of which worked, but the client was blocked until the server finished its task. So the server is made asynchronous.

Server TimeComp.API contains:
FUNCTION StartNetTime
(
);

component.CDEF contains:
provides:
{
api:
{
TimeComp = TimeComp.api [async]
}
}

The server main.c contains:
void TimeComp_StartNetTime (TimeComp_ServerCmdRef_t _cmdRef)
{
// execute the code that won’t return for at least 5 seconds
}

The client calls the function:
TimeComp_StartNetTime ();

This seems to work in isolation. The client continues onto the next instruction without blocking.

However, I have been using the event loop after this call… which stops calling anything on the event queue. I set up a sequence of callbacks which work perfectly when I don’t call the asynchronous routine.

The client calls the function:
TimeComp_StartNetTime (); // test the call to async routine
TestCallbacks(); // test all the callbacks in a sequence

None of my callback tests between applications operate at all. When it wasn’t set up as asynchronous, I could see all the callbacks operate, with a 5 second pause whilst the function was blocked.

I have tried using the autogenerated RESPOND function, but it doesn’t like the “implicit call”.

Is there something I have missed about async?
Is the client still waiting for a response from the server?
Is the queue used for the response to come back to the client?
What do I need to do to make it work?

I personally haven’t used the async feature before. The config tree feature provides a working example of the async feature in use.

The configTree/Component.cdef uses the async keyword. You can look at the async implementation of the api as well.

Thanks dfrey,

After looking at the mangOH configTree source code, it shows that the Respond function is called at the end of the routine:

void TimeComp_StartNetTime (TimeComp_ServerCmdRef_t _cmdRef)
{
// execute the code that won’t return for at least 5 seconds
TimeComp_StartNetTimeRespond (_cmdRef);
}

This seems to operate correctly now.

Hi Andrew

We put together the following test app to check out the behaviour of async

One benefit of async is that the calling function (client) can be returned to early so that it’s event loop isn’t blocked - whilst the called function (server) can block and return later

Thanks John, that helped me understand it a bit better.