Skip to content

Commit c25537b

Browse files
authored
chore: drop bluebird and lodash (#57)
* chore: drop bluebird * chore: drop lodash * address review comments
1 parent 07b47dc commit c25537b

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

lib/asyncbox.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import B from 'bluebird';
2-
import _ from 'lodash';
31
import type {LongSleepOptions, WaitForConditionOptions} from './types.js';
42

53
const LONG_SLEEP_THRESHOLD = 5000; // anything over 5000ms will turn into a spin
@@ -9,7 +7,7 @@ const LONG_SLEEP_THRESHOLD = 5000; // anything over 5000ms will turn into a spin
97
* @param ms - The number of milliseconds to wait
108
*/
119
export async function sleep(ms: number): Promise<void> {
12-
return await B.delay(ms);
10+
return new Promise((resolve) => setTimeout(resolve, ms));
1311
}
1412

1513
/**
@@ -40,7 +38,7 @@ export async function longSleep(
4038
const post = Date.now();
4139
timeLeft = endAt - post;
4240
elapsedMs = elapsedMs + (post - pre);
43-
if (_.isFunction(progressCb)) {
41+
if (typeof progressCb === 'function') {
4442
progressCb({elapsedMs, timeLeft, progress: elapsedMs / ms});
4543
}
4644
} while (timeLeft > 0);
@@ -176,11 +174,12 @@ export async function waitForCondition<T>(
176174
condFn: () => Promise<T> | T,
177175
options: WaitForConditionOptions = {},
178176
): Promise<T> {
179-
const opts: WaitForConditionOptions & {waitMs: number; intervalMs: number} = _.defaults(options, {
180-
waitMs: 5000,
181-
intervalMs: 500,
182-
});
183-
const debug = opts.logger ? opts.logger.debug.bind(opts.logger) : _.noop;
177+
const opts: WaitForConditionOptions & {waitMs: number; intervalMs: number} = {
178+
...options,
179+
waitMs: typeof options.waitMs === 'number' ? options.waitMs : 5000,
180+
intervalMs: typeof options.intervalMs === 'number' ? options.intervalMs : 500,
181+
};
182+
const debug = opts.logger ? opts.logger.debug.bind(opts.logger) : () => undefined;
184183
const error = opts.error;
185184
const begunAt = Date.now();
186185
const endAt = begunAt + opts.waitMs;
@@ -194,12 +193,12 @@ export async function waitForCondition<T>(
194193
const remainingTime = endAt - now;
195194
if (now < endAt) {
196195
debug(`Waited for ${waited} ms so far`);
197-
await B.delay(Math.min(opts.intervalMs, remainingTime));
196+
await sleep(Math.min(opts.intervalMs, remainingTime));
198197
return await spin();
199198
}
200199
// if there is an error option, it is either a string message or an error itself
201200
if (error) {
202-
throw _.isString(error) ? new Error(error) : error;
201+
throw typeof error === 'string' ? new Error(error) : error;
203202
}
204203
throw new Error(`Condition unmet after ${waited} ms. Timing out.`);
205204
};

package.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
"lib/**/*",
3030
"build/lib/**/*"
3131
],
32-
"dependencies": {
33-
"bluebird": "^3.5.1",
34-
"lodash": "^4.17.4"
35-
},
3632
"scripts": {
3733
"build": "tsc -b",
3834
"clean": "npm run build -- --clean",
@@ -54,8 +50,6 @@
5450
"@appium/tsconfig": "^1.0.0",
5551
"@semantic-release/changelog": "^6.0.1",
5652
"@semantic-release/git": "^10.0.1",
57-
"@types/bluebird": "^3.5.37",
58-
"@types/lodash": "^4.14.189",
5953
"@types/mocha": "^10.0.10",
6054
"@types/node": "^25.0.3",
6155
"chai": "^6.2.1",

0 commit comments

Comments
 (0)