Skip full period in rate
This commit is contained in:
parent
50f6886b4b
commit
7394b6ef84
@ -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({
|
||||
|
@ -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]);
|
||||
|
Loading…
Reference in New Issue
Block a user