Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameterize next/return #30

Merged
merged 7 commits into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
node_modules
lib
coverage
.rpt2_cache
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
2 changes: 1 addition & 1 deletion packages/limiters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.4.0",
"eslint-config-recommended-plus-types": "^1.0.0",
"eslint-plugin-jest": "^22.17.0",
"eslint-plugin-jest": "^22.19.0",
"eslint-plugin-prettier": "^3.1.1",
"jest": "^24.9.0",
"prettier": "^1.18.2",
Expand Down
10 changes: 5 additions & 5 deletions packages/limiters/src/limiters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,20 @@ export function throttler(

let stopped = false;
stop.then(() => (stopped = true));
for await (let token of Repeater.race([semaphore(limit), stop])) {
for await (const token of Repeater.race([semaphore(limit), stop])) {
if (stopped) {
break;
}

leaking = leak();
token = { ...token, reset: start + wait };
tokens.add(token);
let token1: ThrottleToken = { ...token, reset: start + wait };
tokens.add(token1);
if (cooldown && token.remaining === 0) {
await Promise.race([stop, leaking]);
token = { ...token, remaining: limit };
token1 = { ...token1, remaining: limit };
}

await push(token);
await push(token1);
}

tokens.clear();
Expand Down
2 changes: 1 addition & 1 deletion packages/pubsub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.4.0",
"eslint-config-recommended-plus-types": "^1.0.0",
"eslint-plugin-jest": "^22.17.0",
"eslint-plugin-jest": "^22.19.0",
"eslint-plugin-prettier": "^3.1.1",
"jest": "^24.9.0",
"prettier": "^1.18.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/repeater/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.4.0",
"eslint-config-recommended-plus-types": "^1.0.0",
"eslint-plugin-jest": "^22.17.0",
"eslint-plugin-jest": "^22.19.0",
"eslint-plugin-prettier": "^3.1.1",
"jest": "^24.9.0",
"prettier": "^1.18.2",
Expand Down
22 changes: 11 additions & 11 deletions packages/repeater/src/buffers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export interface RepeaterBuffer<T> {
full: boolean;
empty: boolean;
add(value: T): void;
remove(): T;
add(value: PromiseLike<T> | T): void;
remove(): PromiseLike<T> | T;
}

export class FixedBuffer<T> implements RepeaterBuffer<T> {
private arr: T[] = [];
private arr: (PromiseLike<T> | T)[] = [];

get empty(): boolean {
return this.arr.length === 0;
Expand All @@ -22,15 +22,15 @@ export class FixedBuffer<T> implements RepeaterBuffer<T> {
}
}

add(value: T): void {
add(value: PromiseLike<T> | T): void {
if (this.full) {
throw new Error("Buffer full");
} else {
this.arr.push(value);
}
}

remove(): T {
remove(): PromiseLike<T> | T {
if (this.empty) {
throw new Error("Buffer empty");
}
Expand All @@ -41,7 +41,7 @@ export class FixedBuffer<T> implements RepeaterBuffer<T> {

// TODO: use a circular buffer here
export class SlidingBuffer<T> implements RepeaterBuffer<T> {
private arr: T[] = [];
private arr: (PromiseLike<T> | T)[] = [];

get empty(): boolean {
return this.arr.length === 0;
Expand All @@ -57,15 +57,15 @@ export class SlidingBuffer<T> implements RepeaterBuffer<T> {
}
}

add(value: T): void {
add(value: PromiseLike<T> | T): void {
while (this.arr.length >= this.capacity) {
this.arr.shift();
}

this.arr.push(value);
}

remove(): T {
remove(): PromiseLike<T> | T {
if (this.empty) {
throw new Error("Buffer empty");
}
Expand All @@ -75,7 +75,7 @@ export class SlidingBuffer<T> implements RepeaterBuffer<T> {
}

export class DroppingBuffer<T> implements RepeaterBuffer<T> {
private arr: T[] = [];
private arr: (PromiseLike<T> | T)[] = [];

get empty(): boolean {
return this.arr.length === 0;
Expand All @@ -91,13 +91,13 @@ export class DroppingBuffer<T> implements RepeaterBuffer<T> {
}
}

add(value: T): void {
add(value: PromiseLike<T> | T): void {
if (this.arr.length < this.capacity) {
this.arr.push(value);
}
}

remove(): T {
remove(): PromiseLike<T> | T {
if (this.empty) {
throw new Error("Buffer empty");
}
Expand Down
Loading