grunt-throttle
grunt-throttle copied to clipboard
add optional latency parameter
This closes #3 Simplest possible implementation of network latency simulation.
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.
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).
oops, misclick ;)