Last active
September 1, 2015 21:36
-
-
Save roelvan/28f89524f8fcc5e5177a to your computer and use it in GitHub Desktop.
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
# on the server: server.coffee | |
Metrics = (name, aggregationQuery, collection, interval) -> | |
@name = name | |
@aggregationQuery = aggregationQuery | |
@collection = collection | |
@interval = interval or 1000*10 | |
@_collectionName = 'metrics-transport' | |
Metrics.prototype._getCollectionName = -> "metrics-#{@name}" | |
Metrics.prototype._publishCursor = (sub) -> | |
result = @collection.aggregate @aggregationQuery | |
sub.added @_collectionName, @name, result: result | |
sub.ready() | |
handle = Meteor.setInterval => | |
result = @collection.aggregate @aggregationQuery | |
sub.changed @_collectionName, @name, result: result | |
, @interval | |
sub.onStop -> Meteor.clearTimeout handle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment