cowboy icon indicating copy to clipboard operation
cowboy copied to clipboard

Support inactivity timer events in cowboy_loop handlers

Open jwheare opened this issue 4 years ago • 0 comments

gen_server/gen_statem/receive have features where you can setup an automatic event to fire after a certain period of inactivity.

This would be convenient in cowboy_loop to implement idle messages to keep sse connections from being closed by browsers.

It's possible to just send regular idle messages blindly with send_after/start_timer, but a config option that uses a common pattern in OTP would be neater and require less boilerplate code in handlers.

I believe this could be implemented with a customisable receive...after clause in the main handler loop:

https://github.com/ninenines/cowboy/blob/c47f1e5fb824f24e97b8097c3a0886a2a022fa10/src/cowboy_loop.erl#L56-L70

jwheare avatar Oct 12 '20 11:10 jwheare