Skip to content

Instantly share code, notes, and snippets.

View mattpodwysocki's full-sized avatar

Matthew Podwysocki mattpodwysocki

View GitHub Profile
import { IterableX } from './iterable';
import { AsyncSink } from './asyncsink';
import { AsyncIterableX } from './asynciterable';
import { OrderedIterableX } from './iterable/orderby';
import { OrderedAsyncIterableX } from './asynciterable/orderby';
export {
IterableX as Iterable,
AsyncSink,
AsyncIterableX as AsyncIterable,
'use strict';
interface AsyncSubscription {
unsubscribeAsync(): Promise<void>;
}
interface AsyncObserver<T> {
next(value: T): Promise<void>;
error(error: any): Promise<void>;
complete(): Promise<void>;
import { fs } from 'fs';
import { AsyncSink } from 'ix/asyncsink';
function fromReadableStream(path: string, options: any) {
const sink = new AsyncSink();
const stream = fs.createReadStream(path, options);
stream.on('readable', () => {
let data = null;
while ((data = stream.read()) !== null) {
sink.write(data);
/**
* @ignore
*/
export function returnIterator<T>(it: Iterator<T>) {
if (typeof it.return === 'function') {
it.return();
}
}
/**
import { IterableX } from '../iterable';
function returnIterator<T>(it: Iterator<T>) {
if (typeof it.return === 'function') {
it.return();
}
}
class CatchIterable<TSource> extends IterableX<TSource> {
private _source: Iterable<Iterable<TSource>>;
console.js:106
`${util.format.apply(null, args)}\n`,
^
RangeError: Maximum call stack size exceeded
at Console.log (console.js:106:24)
at log (/Users/matthewp/GitHub/rx/IxJS/node_modules/fancy-log/index.js:15:15)
at Object.module.exports [as log] (/Users/matthewp/GitHub/rx/IxJS/node_modules/gulp-util/lib/log.js:11:14)
at Gulp.<anonymous> (/Users/matthewp/GitHub/rx/IxJS/node_modules/gulp/bin/gulp.js:197:11)
at emitOne (events.js:115:13)
'use strict';
import { AsyncIterableX } from '../asynciterable';
class TakeUntilAsyncIterable<TSource> extends AsyncIterableX<TSource> {
private _source: AsyncIterable<TSource>;
private _other: Promise<any>;
constructor(source: AsyncIterable<TSource>, other: Promise<any>) {
super();
'use strict';
import * as test from 'tape';
import { of } from '../../dist/cjs/asynciterable/of';
import { race } from '../../dist/cjs/asynciterable/race';
import { hasNext, noNext } from '../asynciterablehelpers';
function delayValue<T>(value: T, time: number) {
return new Promise<T>(resolve => setTimeout(() => resolve(value), time));
}
@mattpodwysocki
mattpodwysocki / example.ts
Last active June 15, 2017 22:29
Reimagining events as async iterables
const EventEmitter = require('events').EventEmitter;
const fromEventPattern = require('ix/asynciterable/fromeventpattern').fromEventPattern;
// Get Async Iterable
const e = new EventEmitter();
const ai = fromEventPattern(
h => e.addListener('data', h),
h => e.removeListener('data', h)
);
@mattpodwysocki
mattpodwysocki / ofentries.ts
Created June 12, 2017 19:08
Adds ofEntries, ofKeys and ofValues to Iterable/AsyncIterable
'use strict';
import { IterableX } from '../iterable';
import { map } from './map';
function makeTuple<TFirst, TSecond>(x: TFirst, y: TSecond): [TFirst, TSecond] {
return [x, y];
}
class OfEntriesIterable<TSource> extends IterableX<[string, TSource]> {