Skip to content

Instantly share code, notes, and snippets.

View mattpodwysocki's full-sized avatar

Matthew Podwysocki mattpodwysocki

View GitHub Profile
import { ReduceOptions } from './reduceoptions';
import { wrapWithAbort } from './operators/withabort';
export async function reduce<T, R = T>(
source: AsyncIterable<T>,
options: ReduceOptions<T, R>
): Promise<R> {
const { seed, signal, callback } = options;
const hasSeed = options.hasOwnProperty('seed');
let i = 0;
import { AbortError } from '../aborterror';
export function sleep(dueTime: number, signal?: AbortSignal) {
return new Promise<void>((resolve, reject) => {
if (signal?.aborted) {
reject(new AbortError());
}
const id = setTimeout(() => {
if (signal?.aborted) {
export class AbortError extends Error {
constructor() {
super();
Object.setPrototypeOf(this, AbortError.prototype);
this.message = 'The operation has been aborted';
}
}
export function throwIfAborted(signal?: AbortSignal) {
if (signal?.aborted) {
// New Way
export function orderBy<TSource>(
key: keyof TSource
): UnaryFunction<AsyncIterable<TSource>, OrderedAsyncIterableX<TKey, TSource>> {
return function orderByOperatorFunction(source: AsyncIterable<TSource>) {
return new OrderedAsyncIterableX<TSource>(source, key, false);
};
}
// Old way
export interface GroupByOptions<TSource, TKey, TValue = TSource> {
keySelector: (value: TSource) => TKey | Promise<TKey>;
elementSelector?: (value: TSource) => TValue | Promise<TValue>;
signal?: AbortSignal;
}
export interface GroupByOptionsWithSelector<TSource, TKey, TValue, TResult> {
keySelector: (value: TSource) => TKey | Promise<TKey>;
elementSelector?: (value: TSource) => TValue | Promise<TValue>;
resultSelector?: (
import { AbortError } from "../util/aborterror";
export function delay(action: () => void, dueTime: number, signal?: AbortSignal) {
return new Promise((resolve, reject) => {
if (signal?.aborted) {
throw new AbortError();
}
const id = setTimeout(() => {
if (signal?.aborted) {
@mattpodwysocki
mattpodwysocki / concatcall.ts
Last active February 3, 2020 16:17
Adding basic cancellation to IxJS AsyncIterable
import { AsyncIterableX } from '../asynciterablex';
import { OperatorAsyncFunction } from '../../interfaces';
import { wrapWithAbort } from './withabort';
export class ConcatAllAsyncIterable<TSource> extends AsyncIterableX<TSource> {
private _source: AsyncIterable<AsyncIterable<TSource>>;
private _signal?: AbortSignal;
constructor(source: AsyncIterable<AsyncIterable<TSource>>, signal?: AbortSignal) {
super();
function Get-Files($path = $pwd) {
foreach ($item in Get-ChildItem $path) {
if (Test-Path $item.FullName -PathType Container) {
Get-Files $item.FullName
} else {
$item
}
}
}
const move$ = fromEvent(document, 'mousemove')
const down$ = fromEvent(document, 'mousedown')
const up$ = fromEvent(document, 'mouseup')
const mergeFn = downs => { // In case you want the first position
// If you want to deltas between start and end, you might want a map that captures downs versus moves
return move$.pipe(takeUntil($ups));
};
const paints$ = move$.pipe(
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;