Skip to content

Commit

Permalink
completely removed the need for lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
dougg0k committed Sep 6, 2022
1 parent 5277496 commit d90e261
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 21 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"dayjs": "1.11.5",
"debug": "4.3.4",
"ioredis": "4.28.5",
"lodash": "4.17.21",
"p-queue": "6.6.2",
"p-timeout": "4.1.0",
"rate-limiter-flexible": "2.3.8",
Expand All @@ -50,9 +49,7 @@
"@types/debug": "4.1.7",
"@types/ioredis": "4.28.10",
"@types/jest": "29.0.0",
"@types/lodash": "4.14.184",
"@types/node": "18.7.15",
"@types/set-interval-async": "^1.0.0",
"@types/uuid": "8.3.4",
"@typescript-eslint/eslint-plugin": "5.36.2",
"@typescript-eslint/parser": "5.36.2",
Expand Down
15 changes: 1 addition & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/actions/are-tasks-stalled.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Redis } from 'ioredis';
import { zipWith } from 'lodash';
import { zipWith } from '../utils/general';
import { getTaskAcknowledgedKey } from '../utils/keys';
import { exec } from '../utils/redis';
import { getStallingTaskIds } from './get-stalling-task-ids';
Expand Down
2 changes: 1 addition & 1 deletion src/actions/create-manager.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import debugF from 'debug';
import { Redis } from 'ioredis';
import { set } from 'lodash';
import { Event } from '../domain/events/event';
import { EventType } from '../domain/events/event-type';
import { Manager } from '../domain/manager/manager';
import { TaskResponse } from '../domain/manager/task-response';
import { Task } from '../domain/tasks/task';
import { TaskStatus } from '../domain/tasks/task-status';
import { set } from '../utils/general';
import {
createClientAndLoadLuaScripts,
ensureDisconnected,
Expand Down
3 changes: 1 addition & 2 deletions src/actions/create-worker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import debugF from 'debug';
import { Redis } from 'ioredis';
import { debounce } from 'lodash';
import PQueue from 'p-queue';
import { RateLimiterRedis } from 'rate-limiter-flexible';
import {
Expand All @@ -14,7 +13,7 @@ import { Task } from '../domain/tasks/task';
import { serializeWorker } from '../domain/worker/serialize-worker';
import { Worker } from '../domain/worker/worker';
import { WorkerInstance } from '../domain/worker/worker-instance';
import { createWorkerId, sleep } from '../utils/general';
import { createWorkerId, debounce, sleep } from '../utils/general';
import {
getWorkerKey,
getWorkerPausedChannel,
Expand Down
26 changes: 26 additions & 0 deletions src/utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,29 @@ export const pickBy = (
}
return obj;
};

export const zipWith = (
arr1: Array<any>,
arr2: Array<any>,
fn: (value: any, value2: any) => any,
) => arr1.map((value, index) => fn(value, arr2[index]));

export const set = (object: Record<string, any>, path: string, value: any) => {
/* eslint-disable no-param-reassign */
const [current, ...rest] = path.split('.');
if (rest.length >= 1) {
object[current] = object[current] || {};
set(object[current], rest.join('.'), value);
} else {
object[current] = value;
}
return object;
};

export const debounce = (fn: (args: []) => any, timeout: number) => {
let timer: NodeJS.Timeout;
return (...args: any) => {
clearTimeout(timer);
timer = setTimeout(() => fn(args), timeout);
};
};

0 comments on commit d90e261

Please sign in to comment.