nats-io / nats.c

A C client for NATS
Apache License 2.0
390 stars 137 forks source link

single-threaded mode? #712

Open jlevon opened 9 months ago

jlevon commented 9 months ago

Proposed change

I'm curious if there's been any discussion of a single-threaded mode for when using an event loop. We would like to integrate with our (private) event loop instead of using a threaded model.

While the existing SetEventLoop callbacks work great for my needs (which is just publishing to a jetstream stream, no need for replies or any other stuff), with SendASAP set, this all falls apart during reconnection handling, where the reconnection happens off thread. This includes ping interval processing.

The example libuv code (thank you for writing this!) goes through some gymnastics to make sure the reconnection is processed back on the main event thread safely, but this would all be much simpler if for example, the event loop could process the timers itself rather than on the thread.

I'm not quite clear on the asyncCB and GC threads, but apparently I haven't hit them actually being used yet.

Use case

See above.

Contribution

I don't think I understand the core code well enough.