Skip to content

Commit

Permalink
fix: tests and throttle return type
Browse files Browse the repository at this point in the history
  • Loading branch information
nberlette committed Aug 18, 2022
1 parent 84d5342 commit f767bd3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function sleep(
* @see {@link debounce}
*/
export function throttle<T>(
callback: Maybe<Fn<T>>,
callback: Fn<T>,
delay = 250,
debounceMode = false,
noTrailing = false,
Expand Down Expand Up @@ -78,9 +78,9 @@ export function throttle<T>(
/**
* Execute `callback` and update the `lastExec` timestamp.
*/
async function exec() {
function exec() {
lastExec = Date.now();
await callback.apply<any, any[], T>(self as any, args as any[]);
return callback.apply<any, any[], T>(self as any, args as any[]);
}
/**
* If `debounceMode` is true (at begin) this is used to clear the flag
Expand All @@ -100,7 +100,7 @@ export function throttle<T>(
* In throttle mode, if `delay` time has been exceeded, execute
* `callback`.
*/
exec();
return exec();
} else if (noTrailing !== true) {
/**
* In trailing throttle mode, since `delay` time has not been
Expand Down
8 changes: 4 additions & 4 deletions tests/throttle_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
/// <reference lib="esnext" />

import { assertEquals } from "../deps_test.ts";
import { debounce, sleep, throttle } from "../src/throttle.ts";
import { debounce, sleep, throttle } from "../src/promises.ts";

Deno.test({
name: "throttle",
ignore: true,
fn(test) {
const func = (...args: any[]) => {
const func = (...args: any[]): any[] => {
return args;
};
const throttled = throttle(func, 100);
Expand Down Expand Up @@ -39,7 +39,7 @@ Deno.test({
return args;
};
const throttled = throttle(func, 100);
throttled.clear();
throttled.cancel();
const result = throttled(1, 2, 3);
assertEquals(result, [1, 2, 3]);
},
Expand All @@ -53,7 +53,7 @@ Deno.test({
return args;
};
const debounced = debounce(func, 100);
debounced.clear();
debounced.cancel();
const result = debounced(1, 2, 3);
assertEquals(result, [1, 2, 3]);
},
Expand Down

0 comments on commit f767bd3

Please sign in to comment.