@tempest/core
Version:
The core of the Tempest Stream Library
28 lines (23 loc) • 764 B
text/typescript
import { Source, Sink, Scheduler } from '../../src/index'
export interface SourceAssertions<T> {
run?: (sink: Sink<T>, scheduler: Scheduler) => any
dispose?: () => any
}
export class FakeSource<T> implements Source<T> {
constructor (private assertions?: SourceAssertions<T>) {}
static create<T> (assertions?: SourceAssertions<T>) {
return new FakeSource<T>(assertions)
}
run (sink: Sink<T>, scheduler: Scheduler) {
if (this.assertions && typeof this.assertions.run === 'function')
this.assertions.run(sink, scheduler)
const _dispose = this.assertions && typeof this.assertions.dispose === 'function'
? this.assertions.dispose
: Function.prototype
return {
dispose () {
_dispose()
}
}
}
}