import { Subject } from 'rxjs';
import { throttleTime } from 'rxjs/operators';
import { onUnmounted } from 'vue';

export function useThrottle(func: any, time: number) {

  const trigger = new Subject();
  trigger
    .pipe(
      throttleTime(time)
    )
    .subscribe(e => func(e))

  const next = (e: any) => trigger.next(e);
  
  onUnmounted(() => trigger.complete());

  return next
}