Skip full period in rate

This commit is contained in:
Jerry Kurian 2019-08-16 10:06:23 -04:00
parent 50f6886b4b
commit 7394b6ef84
2 changed files with 5 additions and 5 deletions

View File

@ -9,13 +9,13 @@ import { TransformOptions } from "./baseDefinitions";
*/
export function rate(
targetRate: number = 50,
period: number = 2,
period: number = 1,
options: TransformOptions = {
readableObjectMode: true,
writableObjectMode: true,
},
): Transform {
const deltaMS = ((1 / targetRate) * 1000) / period; // Skip half a period
const deltaMS = ((1 / targetRate) * 1000) / period; // Skip a full period
let total = 0;
const start = performance.now();
return new Transform({

View File

@ -19,7 +19,7 @@ test.cb("rate() sends data at desired rate", t => {
let k = 0;
sourceFast
.pipe(rate(fastRate, 1))
.pipe(rate(fastRate))
.on("data", (element: string[]) => {
const currentRate = (i / (performance.now() - start)) * 1000;
expect(element).to.deep.equal(expectedElements[i]);
@ -30,7 +30,7 @@ test.cb("rate() sends data at desired rate", t => {
.on("error", t.end);
sourceMed
.pipe(rate(medRate, 1))
.pipe(rate(medRate))
.on("data", (element: string[]) => {
const currentRate = (j / (performance.now() - start)) * 1000;
expect(element).to.deep.equal(expectedElements[j]);
@ -41,7 +41,7 @@ test.cb("rate() sends data at desired rate", t => {
.on("error", t.end);
sourceSlow
.pipe(rate(slowRate, 1))
.pipe(rate(slowRate))
.on("data", (element: string[]) => {
const currentRate = (k / (performance.now() - start)) * 1000;
expect(element).to.deep.equal(expectedElements[k]);