yehya / express-longpoll

Lightweight long polling for express.js
ISC License
33 stars 13 forks source link

Added new subscriber callback #6

Open pennyandsean opened 6 years ago

pennyandsean commented 6 years ago

Hey there, I hope you find this useful. We have an application that required the server to return some status information at the end of a long-poll period, say 60s. I guess normally the client would timeout, but we wanted the server to. So we created a callback for when a new client request is made. It might be a bit quick, let me know if you want it tidied up a bit or added to tests. Cheers.

yehya commented 6 years ago

Great idea! Tests would be great as I can't push the changes without the tests. Also since we are adding callbacks I think that there should be callbacks specific to each endpoint so this could be the "GlobalCallback" that runs for all endpoints, and then another that is added when you create an endpoint, for example

longpoll.create("/hello", subscribeCallback1); 
longpoll.create("/world", subscribeCallback2); 
longpoll.setGlobalCallback(globalSubscribeCallback); // or through initial config

I'll take care of the endpoint specific callbacks.

Thanks for making a pull request!