nats.c icon indicating copy to clipboard operation
nats.c copied to clipboard

The async for natsConnection_RequestString

Open portsip opened this issue 4 years ago • 8 comments

Feature Request

Currently, I see there have the natsConnection_RequestString with a given timeout in MS, can it has an async version? Likes natsConnection_RequestString(&reply, nc, "foo", "help", callback, 1000); Once received the reply in 1000 MS or its timeout, the callback will be triggered.

Use Case:

For some large amounts of the sync call will cause the thread blocked

Proposed Change:

Add a callback parameter to the natsConnection_RequestString.

Who Benefits From The Change(s)?

Alternative Approaches

portsip avatar Aug 04 '21 07:08 portsip

Is this for the server or a specific client language?

derekcollison avatar Aug 04 '21 14:08 derekcollison

Is this for the server or a specific client language?

For the C language client.

Thanks

portsip avatar Aug 04 '21 14:08 portsip

ok will move this over to there.

derekcollison avatar Aug 04 '21 14:08 derekcollison

The C client already provides a way to create an async subscription that times out. See natsConnection_SubscribeTimeout. So you could create a subscription on a wildcard subject, and publish your requests using natsConnection_PublishRequestString with a unique token at the end of the reply subject.

Take note of the behavior of the async subscription timeout in the doc. That is, the callback will be invoked with a NULL message if no message is received in the timeout interval specified when creating the subscription. Receiving a message reset this interval, etc..

kozlovic avatar Aug 04 '21 17:08 kozlovic