Détail du package

retry-ts

gcanti274.6kMIT0.1.4

Retry combinators for monadic actions that may fail

fp-ts, functional-programming, Retry combinators

readme

TypeScript port of PureScript's purescript-aff-retry package which in turn is a porting of Haskell's retry package

Example

import { log } from 'fp-ts/Console'
import * as E from 'fp-ts/Either'
import { pipe } from 'fp-ts/function'
import * as O from 'fp-ts/Option'
import * as TE from 'fp-ts/TaskEither'
import { capDelay, exponentialBackoff, limitRetries, Monoid, RetryStatus } from 'retry-ts'
import { retrying } from 'retry-ts/Task'

const policy = capDelay(2000, Monoid.concat(exponentialBackoff(200), limitRetries(5)))

const fakeAPI = TE.left('API errored out')

const logDelay = (status: RetryStatus) =>
  TE.rightIO(
    log(
      pipe(
        status.previousDelay,
        O.map((delay) => `retrying in ${delay} milliseconds...`),
        O.getOrElse(() => 'first attempt...')
      )
    )
  )

const result = retrying(policy, (status) => pipe(logDelay(status), TE.apSecond(fakeAPI)), E.isLeft)

result().then((e) => console.log(e))
/*
first attempt...
retrying in 200 milliseconds...  <= exponentialBackoff
retrying in 400 milliseconds...  <= exponentialBackoff
retrying in 800 milliseconds...  <= exponentialBackoff
retrying in 1600 milliseconds... <= exponentialBackoff
retrying in 2000 milliseconds... <= exponentialBackoff + capDelay
left("API errored out")          <= limitRetries
*/

Documentation

License

The MIT License (MIT)

changelog

Changelog

Tags:

  • [New Feature]
  • [Bug Fix]
  • [Breaking Change]
  • [Documentation]
  • [Internal]
  • [Polish]
  • [Experimental]

Note: Gaps between patch versions are faulty/broken releases. Note: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice.

0.1.4

  • New Feature
    • add ReaderTask support, #11 (@mlegenhausen)

0.1.3

  • Deprecation
    • deprecate monoidRetryPolicy in favour of Monoid (@gcanti)
  • Polish
    • allow import without es6 or lib directory #8 (@mlegenhausen)
    • add /*#__PURE__*/ comments for better tree shaking (@gcanti)

0.1.2

  • Bug Fix
    • don't set target: es6 in tsconfig.build-es6.json (@gcanti)
  • Internal
    • upgrade to latest docs-ts (@gcanti)

0.1.1

  • New Feature
    • add build in ES6 format (@gcanti)

0.1.0

  • Breaking Change
    • upgrade to fp-ts@2.0.0 (@Wenqer)
    • remove TaskEither module (@Wenqer)

0.0.1

Initial release