diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/trace/metric/trace.ts | 5 | ||||
-rw-r--r-- | lib/types/fn/either.ts | 24 |
2 files changed, 12 insertions, 17 deletions
diff --git a/lib/trace/metric/trace.ts b/lib/trace/metric/trace.ts index 6508831..b28d828 100644 --- a/lib/trace/metric/trace.ts +++ b/lib/trace/metric/trace.ts @@ -49,10 +49,7 @@ export class MetricsTrace implements ITrace<MetricsTraceSupplier> { const parentBasedValues = parentBasedMetrics.flatMap((metric) => { const parentStart = this.activeTraces.get(metric.parent!.name)!; - return [ - metric.count.withValue(1.0), - metric.time.withValue(now - parentStart), - ]; + return [metric.count.withValue(1.0), metric.time.withValue(now - parentStart)]; }); const allMetricsToEmit = [...valuesToEmit, ...endedMetricValues, ...parentBasedValues]; diff --git a/lib/types/fn/either.ts b/lib/types/fn/either.ts index ffe06d4..3c39548 100644 --- a/lib/types/fn/either.ts +++ b/lib/types/fn/either.ts @@ -152,20 +152,18 @@ export class Either<E, T> extends _Tagged implements IEither<E, T> { attempts: number = 3, interval: Mapper<number, Promise<void>> = (attempt) => Either.attemptWait(attempt), ): Promise<IEither<E, T>> { - const res: IEither<T, E> = await Array(attempts) - .fill(0) - .reduce( - async (_result, _i, attempt) => { - await interval(attempt); - const result: IEither<T, E> = await _result; - return result.joinRightAsync( - () => s().then((s) => s.swap()), - (res, _prevError) => res, - ); - }, - Promise.resolve(Either.right<T, E>(<E>new Error('No attempts made'))), + let result: IEither<T, E> = Either.right<T, E>(<E>new Error('No attempts made')); + + for (let attempt = 0; attempt < attempts && result.right().present(); attempt++) { + await interval(attempt); + const currentAttempt = await s().then((s) => s.swap()); + result = await result.joinRightAsync( + () => Promise.resolve(currentAttempt), + (res, _prevError) => res, ); - return res.swap(); + } + + return result.swap(); } static attemptWait( |