Created
June 16, 2015 10:22
-
-
Save Mumakil/898ced59c287e10b05e9 to your computer and use it in GitHub Desktop.
Streaming api cleanup example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stream extends process.EventEmitter | |
constructor: (@request, @response, @channels, @user) -> | |
# other initializing code | |
get: -> | |
# start streaming messages in response to a get request | |
# ... | |
# Normal cleanup after stream is closed | |
@response.on 'finish', @cleanup | |
@response.on 'close', @cleanup | |
# Check that we didn't miss a close event | |
@aliveCheck = setInterval(@ensureRequestIsAlive, Stream.ALIVE_CHECK_INTERVAL) | |
ensureRequestIsAlive: => | |
if @request.connection.destroyed | |
stats.increment('disconnect-dead-socket') | |
@cleanup() | |
cleanup: -> | |
# do required cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment