grunt-throttle icon indicating copy to clipboard operation
grunt-throttle copied to clipboard

add optional latency parameter

Open roman01la opened this issue 10 years ago • 3 comments

This closes #3 Simplest possible implementation of network latency simulation.

roman01la avatar Apr 04 '14 13:04 roman01la

It won't work just like this, because the 'end' event on the source end of the pipe must be relayed to the destination end. I've coded up a more complete version - check out the 'latency' branch. I won't merge it yet because I'd like to do some more testing.

It also worries me a bit to use setTimeout for the delay. Maybe it should be a proper queue to avoid issues with fudged up timings. But it's certainly acceptable for a first version.

tjgq avatar Apr 04 '14 20:04 tjgq

You are right, your code is somehow better, but there are a couple of things I noticed:

  • You applying latency for both upstream and downstream connections, which means specified latency is going to be doubled, while it should be a value representing time spent between request and response. Maybe just divide it into half.
  • Running this code reports a warning about too many created event listeners, which is possible memory leak (streams event listeners).

roman01la avatar Apr 05 '14 19:04 roman01la

oops, misclick ;)

roman01la avatar Apr 05 '14 19:04 roman01la