All Projects → gcanti → retry-ts

gcanti / retry-ts

Licence: MIT license
Retry combinators for monadic actions that may fail

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to retry-ts

vscode-fp-ts-codegen
Expands haskell-syntax ADTs to typescript equivalent types definitions using gcanti/fp-ts-codegen
Stars: ✭ 16 (-89.4%)
Mutual labels:  fp-ts
Pico
Take browser screenshots in Javascript 📸
Stars: ✭ 1,807 (+1096.69%)
Mutual labels:  fp-ts
fp-ts-fluture
fp-ts bindings for Fluture
Stars: ✭ 48 (-68.21%)
Mutual labels:  fp-ts
fp-ts-cheatsheet
FP-TS Cheat Sheet
Stars: ✭ 276 (+82.78%)
Mutual labels:  fp-ts
mutoid
Reactive library for data fetching, caching, state management
Stars: ✭ 24 (-84.11%)
Mutual labels:  fp-ts
ts-do
Do like notation for typescript using fp-ts
Stars: ✭ 55 (-63.58%)
Mutual labels:  fp-ts
workshop-edsl-in-typescript
Code template for workshop "Building eDSLs in functional TypeScript"
Stars: ✭ 49 (-67.55%)
Mutual labels:  fp-ts
fp-ts-ramda
Ramda functions reimplemented in fp-ts
Stars: ✭ 129 (-14.57%)
Mutual labels:  fp-ts
purifree
Pointfree type-safe functional programming library for TypeScript - with do notation, HKTs, generic lifts and more
Stars: ✭ 64 (-57.62%)
Mutual labels:  fp-ts
typescript-react-starter
React & TypeScript Starter with webpack, ts-jest and runtime environment variables. It comes with fp-ts ecosystem and pre-configured prettier, eslint, vscode, husky hooks and Dockerfile to build a deployable image of your app
Stars: ✭ 17 (-88.74%)
Mutual labels:  fp-ts

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)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].