Skip to content

Commit

Permalink
feat(LinkedQueue)!: rename to Buffer
Browse files Browse the repository at this point in the history
BREAKING CHANGE
  • Loading branch information
slikts committed Jan 24, 2023
1 parent 68799d7 commit d953603
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
22 changes: 11 additions & 11 deletions src/LinkedQueue.spec.ts → src/Buffer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import LinkedQueue from './LinkedQueue';
import Buffer from './Buffer';

describe('LinkedQueue', () => {
describe('Buffer', () => {
it('constructs', () => {
const q = new LinkedQueue();
expect(q).toBeInstanceOf(LinkedQueue);
const q = new Buffer();
expect(q).toBeInstanceOf(Buffer);
});

it('circulates with a limit of one', () => {
const q = new LinkedQueue(1);
const q = new Buffer(1);
q.enqueue(1);
q.enqueue(2);
q.enqueue(3);
Expand All @@ -18,7 +18,7 @@ describe('LinkedQueue', () => {
});

it('circulates with a limit of two', () => {
const q = new LinkedQueue(2);
const q = new Buffer(2);
q.enqueue(1);
q.enqueue(2);
q.enqueue(3);
Expand All @@ -32,12 +32,12 @@ describe('LinkedQueue', () => {
});

it('empty throws', () => {
const q = new LinkedQueue();
const q = new Buffer();
expect(() => q.dequeue()).toThrow();
});

it(`doesn't circulate without a limit`, () => {
const q = new LinkedQueue();
const q = new Buffer();
q.enqueue(1);
q.enqueue(2);
q.enqueue(3);
Expand All @@ -48,7 +48,7 @@ describe('LinkedQueue', () => {
});

it(`clears`, () => {
const q = new LinkedQueue();
const q = new Buffer();
q.enqueue(1);
q.enqueue(2);
q.clear();
Expand All @@ -57,7 +57,7 @@ describe('LinkedQueue', () => {
});

it(`foreaches`, () => {
const q = new LinkedQueue();
const q = new Buffer();
q.enqueue(1);
q.enqueue(2);
let n = 0;
Expand All @@ -66,7 +66,7 @@ describe('LinkedQueue', () => {
});

it('iterates', () => {
const q = new LinkedQueue();
const q = new Buffer();
q.enqueue(1);
q.enqueue(2);
expect([...q]).toEqual([1, 2]);
Expand Down
4 changes: 2 additions & 2 deletions src/LinkedQueue.ts → src/Buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import fastList from 'fast-list';

/**
* First-in, first-out (FIFO) buffer (queue) with default item values.
* Optionally circular based on {@link LinkedQueue.limit}.
* Optionally circular based on {@link Buffer.limit}.
*/
export default class LinkedQueue<A> {
export default class Buffer<A> {
#list: fastList.List<A>;
length = 0;

Expand Down
10 changes: 5 additions & 5 deletions src/adapters/Channel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Deferred from '../Deferred';
import LinkedQueue from '../LinkedQueue';
import Buffer from '../Buffer';
import { PushAdapter, doneResult } from '../common';
import fromDom from '../fromDom';
import fromEmitter from '../fromEmitter';
Expand All @@ -26,9 +26,9 @@ export interface Unpushed<A> {
*/
export default class Channel<A> implements PushAdapter<A> {
/** Pushed results waiting for pulls to resolve */
readonly pushBuffer: LinkedQueue<Unpushed<A>>;
readonly pushBuffer: Buffer<Unpushed<A>>;
/** Unresolved pulls waiting for results to be pushed */
readonly pullBuffer: LinkedQueue<Deferred<IteratorResult<A>>>;
readonly pullBuffer: Buffer<Deferred<IteratorResult<A>>>;
/** Determines whether new values can be pushed or pulled */
private closed = false;

Expand All @@ -39,8 +39,8 @@ export default class Channel<A> implements PushAdapter<A> {
/** Limit (bounds) after which the oldest buffered value is dropped. */
limit = Infinity,
) {
this.pushBuffer = new LinkedQueue(limit);
this.pullBuffer = new LinkedQueue(limit);
this.pushBuffer = new Buffer(limit);
this.pullBuffer = new Buffer(limit);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export { default as Multicast } from './adapters/Multicast';
export { default as Channel, Unpushed, WrappedBalancer } from './adapters/Channel';
export { default as LastResult } from './adapters/LastResult';
export { default as Deferred } from './Deferred';
export { default as LinkedQueue } from './LinkedQueue';
export { default as Buffer } from './Buffer';
export { default as fromDom, Target, Listener, EventMap } from './fromDom';
export { default as fromEmitter } from './fromEmitter';
export { PushAdapter } from './common';

0 comments on commit d953603

Please sign in to comment.