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(
|
export function rate(
|
||||||
targetRate: number = 50,
|
targetRate: number = 50,
|
||||||
period: number = 2,
|
period: number = 1,
|
||||||
options: TransformOptions = {
|
options: TransformOptions = {
|
||||||
readableObjectMode: true,
|
readableObjectMode: true,
|
||||||
writableObjectMode: true,
|
writableObjectMode: true,
|
||||||
},
|
},
|
||||||
): Transform {
|
): Transform {
|
||||||
const deltaMS = ((1 / targetRate) * 1000) / period; // Skip half a period
|
const deltaMS = ((1 / targetRate) * 1000) / period; // Skip a full period
|
||||||
let total = 0;
|
let total = 0;
|
||||||
const start = performance.now();
|
const start = performance.now();
|
||||||
return new Transform({
|
return new Transform({
|
||||||
|
@ -19,7 +19,7 @@ test.cb("rate() sends data at desired rate", t => {
|
|||||||
let k = 0;
|
let k = 0;
|
||||||
|
|
||||||
sourceFast
|
sourceFast
|
||||||
.pipe(rate(fastRate, 1))
|
.pipe(rate(fastRate))
|
||||||
.on("data", (element: string[]) => {
|
.on("data", (element: string[]) => {
|
||||||
const currentRate = (i / (performance.now() - start)) * 1000;
|
const currentRate = (i / (performance.now() - start)) * 1000;
|
||||||
expect(element).to.deep.equal(expectedElements[i]);
|
expect(element).to.deep.equal(expectedElements[i]);
|
||||||
@ -30,7 +30,7 @@ test.cb("rate() sends data at desired rate", t => {
|
|||||||
.on("error", t.end);
|
.on("error", t.end);
|
||||||
|
|
||||||
sourceMed
|
sourceMed
|
||||||
.pipe(rate(medRate, 1))
|
.pipe(rate(medRate))
|
||||||
.on("data", (element: string[]) => {
|
.on("data", (element: string[]) => {
|
||||||
const currentRate = (j / (performance.now() - start)) * 1000;
|
const currentRate = (j / (performance.now() - start)) * 1000;
|
||||||
expect(element).to.deep.equal(expectedElements[j]);
|
expect(element).to.deep.equal(expectedElements[j]);
|
||||||
@ -41,7 +41,7 @@ test.cb("rate() sends data at desired rate", t => {
|
|||||||
.on("error", t.end);
|
.on("error", t.end);
|
||||||
|
|
||||||
sourceSlow
|
sourceSlow
|
||||||
.pipe(rate(slowRate, 1))
|
.pipe(rate(slowRate))
|
||||||
.on("data", (element: string[]) => {
|
.on("data", (element: string[]) => {
|
||||||
const currentRate = (k / (performance.now() - start)) * 1000;
|
const currentRate = (k / (performance.now() - start)) * 1000;
|
||||||
expect(element).to.deep.equal(expectedElements[k]);
|
expect(element).to.deep.equal(expectedElements[k]);
|
||||||
|
Loading…
Reference in New Issue
Block a user