From 543af9f06f3c2a12cbb83a6befe6e7b19b89b27c Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 29 Dec 2023 01:00:15 +0100 Subject: [PATCH] Changed name of new reflectStatus function --- CHANGELOG.md | 2 +- modern-async.d.ts | 8 ++++---- src/findInternal.mjs | 8 ++++---- src/mapGenerator.mjs | 8 ++++---- src/modern-async.mjs | 2 +- src/{reflectStatus.mjs => reflectAsyncStatus.mjs} | 8 ++++---- ...lectStatus.test.mjs => reflectAsyncStatus.test.mjs} | 10 +++++----- 7 files changed, 23 insertions(+), 23 deletions(-) rename src/{reflectStatus.mjs => reflectAsyncStatus.mjs} (88%) rename src/{reflectStatus.test.mjs => reflectAsyncStatus.test.mjs} (68%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8957d0a..0321ec0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## next version -* Added `reflectStatus()` function. +* Added `reflectAsyncStatus()` function. ## 1.1.4 diff --git a/modern-async.d.ts b/modern-async.d.ts index 5423c39..16fe2ef 100644 --- a/modern-async.d.ts +++ b/modern-async.d.ts @@ -220,9 +220,9 @@ declare module "timeoutPrecise" { export default timeoutPrecise; function timeoutPrecise(fct: () => Promise | T, amount: number): Promise; } -declare module "reflectStatus" { - export default reflectStatus; - function reflectStatus(fct: () => Promise | T): Promise>; +declare module "reflectAsyncStatus" { + export default reflectAsyncStatus; + function reflectAsyncStatus(fct: () => Promise | T): Promise>; } declare module "modern-async" { export { default as asyncIterableWrap } from "asyncIterableWrap"; @@ -269,5 +269,5 @@ declare module "modern-async" { export { default as TimeoutError } from "TimeoutError"; export { default as timeoutPrecise } from "timeoutPrecise"; export { default as toArray } from "toArray"; - export { default as reflectStatus } from "reflectStatus"; + export { default as reflectAsyncStatus } from "reflectAsyncStatus"; } diff --git a/src/findInternal.mjs b/src/findInternal.mjs index ee4ee6e..d4b1e26 100644 --- a/src/findInternal.mjs +++ b/src/findInternal.mjs @@ -3,7 +3,7 @@ import assert from 'nanoassert' import asyncWrap from './asyncWrap.mjs' import asyncIterableWrap from './asyncIterableWrap.mjs' import getQueue from './getQueue.mjs' -import reflectStatus from './reflectStatus.mjs' +import reflectAsyncStatus from './reflectAsyncStatus.mjs' /** * @ignore @@ -40,7 +40,7 @@ async function findInternal (iterable, iteratee, queueOrConcurrency, ordered) { const identifier = waitListIndex waitListIndex += 1 const p = (async () => { - return [identifier, await reflectStatus(fct)] + return [identifier, await reflectAsyncStatus(fct)] })() assert(!waitList.has(identifier), 'waitList already contains identifier') waitList.set(identifier, p) @@ -72,7 +72,7 @@ async function findInternal (iterable, iteratee, queueOrConcurrency, ordered) { const removed = scheduledList.delete(index) assert(removed, 'Couldn\'t find index in scheduledList for removal') - const snapshot = await reflectStatus(() => iteratee(value, index, iterable)) + const snapshot = await reflectAsyncStatus(() => iteratee(value, index, iterable)) scheduledCount -= 1 insertInResults(index, value, snapshot) @@ -103,7 +103,7 @@ async function findInternal (iterable, iteratee, queueOrConcurrency, ordered) { const fetch = () => { fetching = true addToWaitList(async () => { - const snapshot = await reflectStatus(() => it.next()) + const snapshot = await reflectAsyncStatus(() => it.next()) fetching = false if (snapshot.status === 'fulfilled') { const { value, done } = snapshot.value diff --git a/src/mapGenerator.mjs b/src/mapGenerator.mjs index ef3ea71..77190d6 100644 --- a/src/mapGenerator.mjs +++ b/src/mapGenerator.mjs @@ -4,7 +4,7 @@ import asyncWrap from './asyncWrap.mjs' import asyncIterableWrap from './asyncIterableWrap.mjs' import getQueue from './getQueue.mjs' import Queue from './Queue.mjs' -import reflectStatus from './reflectStatus.mjs' +import reflectAsyncStatus from './reflectAsyncStatus.mjs' /** * Produces a an async iterator that will return each value or `iterable` after having processed them through @@ -78,7 +78,7 @@ async function * mapGenerator (iterable, iteratee, queueOrConcurrency = 1, order const identifier = waitListIndex waitListIndex += 1 const p = (async () => { - return [identifier, await reflectStatus(fct)] + return [identifier, await reflectAsyncStatus(fct)] })() assert(!waitList.has(identifier), 'waitList contains identifier') waitList.set(identifier, p) @@ -110,7 +110,7 @@ async function * mapGenerator (iterable, iteratee, queueOrConcurrency = 1, order const removed = scheduledList.delete(index) assert(removed, 'Couldn\'t find index in scheduledList for removal') - const snapshot = await reflectStatus(() => iteratee(value, index, iterable)) + const snapshot = await reflectAsyncStatus(() => iteratee(value, index, iterable)) scheduledCount -= 1 insertInResults(index, value, snapshot) @@ -141,7 +141,7 @@ async function * mapGenerator (iterable, iteratee, queueOrConcurrency = 1, order const fetch = () => { fetching = true addToWaitList(async () => { - const snapshot = await reflectStatus(() => it.next()) + const snapshot = await reflectAsyncStatus(() => it.next()) fetching = false if (snapshot.status === 'fulfilled') { const { value, done } = snapshot.value diff --git a/src/modern-async.mjs b/src/modern-async.mjs index c374829..1349521 100644 --- a/src/modern-async.mjs +++ b/src/modern-async.mjs @@ -43,4 +43,4 @@ export { default as timeout } from './timeout.mjs' export { default as TimeoutError } from './TimeoutError.mjs' export { default as timeoutPrecise } from './timeoutPrecise.mjs' export { default as toArray } from './toArray.mjs' -export { default as reflectStatus } from './reflectStatus.mjs' +export { default as reflectAsyncStatus } from './reflectAsyncStatus.mjs' diff --git a/src/reflectStatus.mjs b/src/reflectAsyncStatus.mjs similarity index 88% rename from src/reflectStatus.mjs rename to src/reflectAsyncStatus.mjs index ab37364..4f59288 100644 --- a/src/reflectStatus.mjs +++ b/src/reflectAsyncStatus.mjs @@ -22,11 +22,11 @@ * @returns {Promise} A promise that will always be resolved with an object containing * a snapshot of the original promise state. * @example - * import { reflectStatus, map, sleep } from 'modern-async' + * import { reflectAsyncStatus, map, sleep } from 'modern-async' * * const array = [1, 2, 3] * - * const result = await map(array, (v) => reflectStatus(async () => { + * const result = await map(array, (v) => reflectAsyncStatus(async () => { * await sleep(10) // waits 10ms * if (v % 2 === 0) { // throws error on some values * throw Error("error") @@ -42,7 +42,7 @@ * // { status: 'fulfilled', value: 3 } * // ] */ -async function reflectStatus (fct) { +async function reflectAsyncStatus (fct) { try { const res = await fct() return { @@ -57,4 +57,4 @@ async function reflectStatus (fct) { } } -export default reflectStatus +export default reflectAsyncStatus diff --git a/src/reflectStatus.test.mjs b/src/reflectAsyncStatus.test.mjs similarity index 68% rename from src/reflectStatus.test.mjs rename to src/reflectAsyncStatus.test.mjs index 1f1c10e..e4089f0 100644 --- a/src/reflectStatus.test.mjs +++ b/src/reflectAsyncStatus.test.mjs @@ -1,10 +1,10 @@ import { expect, test } from '@jest/globals' -import reflectStatus from './reflectStatus.mjs' +import reflectAsyncStatus from './reflectAsyncStatus.mjs' import delay from './delay.mjs' -test('reflectStatus base test', async () => { - const res1 = await reflectStatus(async () => { +test('reflectAsyncStatus base test', async () => { + const res1 = await reflectAsyncStatus(async () => { await delay() return 3 }) @@ -15,8 +15,8 @@ test('reflectStatus base test', async () => { expect(res1.reason).toBeUndefined() }) -test('reflectStatus falure', async () => { - const res1 = await reflectStatus(async () => { +test('reflectAsyncStatus falure', async () => { + const res1 = await reflectAsyncStatus(async () => { await delay() throw new Error('error') })