rstudio / httpuv

HTTP and WebSocket server package for R
Other
229 stars 86 forks source link

Figuring out when the server started #167

Closed Pensarfeo closed 5 years ago

Pensarfeo commented 6 years ago

Hi, is there a way to know when the server started and, for example, print a message?

wch commented 6 years ago

Can you just print the message right before calling runServer()?

Pensarfeo commented 6 years ago

The two things are not the same. Is the answer no then?

wch commented 6 years ago

I guess it's not clear to me what you mean by "when the server started." I meant the time that the application started (via runServer). Do you mean something else, like the time that the server booted up?

Pensarfeo commented 6 years ago

Yeah, after the server is up and its ready to respond! For anyone familiar with node, that's when the string 'listening on 3001' is printed (server.listen is the equivalent of runServer)

server.listen(3001, () => console.log('listening on 3001'))
wch commented 5 years ago

My understanding of your example is that the call to server.listen() is asynchronous, and console.log() will be executed as soon as the server starts.

httpuv is different. runServer() starts the server synchronously, so when it returns, it will be listening on the port. So you can put a cat() or print() right after the call to runServer().