Skip to content

Instantly share code, notes, and snippets.

@christo8989
Last active April 4, 2020 00:53
Show Gist options
  • Save christo8989/2c6111ce6727542464ccb8ba5e2dda0c to your computer and use it in GitHub Desktop.
Save christo8989/2c6111ce6727542464ccb8ba5e2dda0c to your computer and use it in GitHub Desktop.
import { OperatorFunction, SchedulerLike, concat } from "rxjs";
import { async } from "rxjs/internal/scheduler/async";
import { debounceTime, publish, take } from "rxjs/operators";
export function debounceTimeAfter<T>(
amount: number,
dueTime: number,
scheduler: SchedulerLike = async,
): OperatorFunction<T, T> {
return publish(value =>
concat(
value.pipe(take(amount)),
value.pipe(debounceTime(dueTime, scheduler)),
)
);
}
export function debounceTimeAfterFirst<T>(
dueTime: number,
scheduler: SchedulerLike = async,
): OperatorFunction<T, T> {
return debounceTimeAfter<T>(1, dueTime, scheduler);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment