Skip to content

Commit

Permalink
Changed name of new reflectStatus function
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-van committed Dec 29, 2023
1 parent f879754 commit 543af9f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## next version

* Added `reflectStatus()` function.
* Added `reflectAsyncStatus()` function.

## 1.1.4

Expand Down
8 changes: 4 additions & 4 deletions modern-async.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ declare module "timeoutPrecise" {
export default timeoutPrecise;
function timeoutPrecise<T>(fct: () => Promise<T> | T, amount: number): Promise<T>;
}
declare module "reflectStatus" {
export default reflectStatus;
function reflectStatus<T>(fct: () => Promise<T> | T): Promise<PromiseSettledResult<T>>;
declare module "reflectAsyncStatus" {
export default reflectAsyncStatus;
function reflectAsyncStatus<T>(fct: () => Promise<T> | T): Promise<PromiseSettledResult<T>>;
}
declare module "modern-async" {
export { default as asyncIterableWrap } from "asyncIterableWrap";
Expand Down Expand Up @@ -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";
}
8 changes: 4 additions & 4 deletions src/findInternal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/mapGenerator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/modern-async.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
8 changes: 4 additions & 4 deletions src/reflectStatus.mjs → src/reflectAsyncStatus.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
* @returns {Promise<any>} 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")
Expand All @@ -42,7 +42,7 @@
* // { status: 'fulfilled', value: 3 }
* // ]
*/
async function reflectStatus (fct) {
async function reflectAsyncStatus (fct) {
try {
const res = await fct()
return {
Expand All @@ -57,4 +57,4 @@ async function reflectStatus (fct) {
}
}

export default reflectStatus
export default reflectAsyncStatus
10 changes: 5 additions & 5 deletions src/reflectStatus.test.mjs → src/reflectAsyncStatus.test.mjs
Original file line number Diff line number Diff line change
@@ -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
})
Expand All @@ -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')
})
Expand Down

0 comments on commit 543af9f

Please sign in to comment.