“Erich L.” [email protected] writes:
way to stop the server from running such actions when the browser is
closed? (The logger.info was just an example. It could be anything
When you close a page showing on the browser, the browser may or may
not close the connection to your server. If it does not, then you
can’t tell whether a page has been closed.
If it does, then you have to perform IO operation to detect the
If you really care, you could surround the critical code with guard
code that tries to detect connection closing (IO::select for
read-readyness and performing IO#sysread(nonzero length) on such IO
object returns a 0-length string).
But there is still no fool-proof way to detect a user closing a
that won’t be invoked when the browser is closed).