Skip to content

Commit

Permalink
Use ThrottleGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
tjgq committed Oct 22, 2013
1 parent 08c09c2 commit 7d6fa8e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tasks/throttle.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
'use strict';

var net = require('net');
var Throttle = require('stream-throttle');
var ThrottleGroup = require('stream-throttle').ThrottleGroup;

module.exports = function(grunt) {

grunt.registerMultiTask('throttle', 'Grunt plugin for testing under a throttled connection.', function() {

var self = this;

var upThrottle = new ThrottleGroup({rate: self.data.upstream});
var downThrottle = new ThrottleGroup({rate: self.data.downstream});

var server = net.createServer(function (local) {
var remote = net.createConnection({host: self.data.remote_host, port: self.data.remote_port});

var localThrottle = new Throttle({rate: self.data.upstream});
var remoteThrottle = new Throttle({rate: self.data.downstream});
var localThrottle = upThrottle.throttle();
var remoteThrottle = downThrottle.throttle();

local.pipe(localThrottle).pipe(remote);
remote.pipe(remoteThrottle).pipe(local);
Expand Down

0 comments on commit 7d6fa8e

Please sign in to comment.