since import * as T from 'fp-ts/lib/Task' ; import * as O from 'fp-ts/lib/Option' ; import { pipe } from 'fp-ts/lib/pipeable' ; import { applyPolicy , defaultRetryStatus , RetryPolicy , RetryStatus } from '.' ; since export function applyAndDelay ( policy , status ) { const newStatus = applyPolicy ( policy , status ) ; return pipe ( newStatus . previousDelay , O . fold ( ( ) => T . task . of ( newStatus ) , ( millis ) => T . delay ( millis ) ( T . task . of ( newStatus ) ) ) ) ; } since export function retrying < A > ( policy , action , check ) { const go = ( status ) : T . Task < A > => pipe ( status , action , T . chain ( ( a ) => { if ( check ( a ) ) { return pipe ( applyAndDelay ( policy , status ) , T . chain ( ( status ) => pipe ( status . previousDelay , O . fold ( ( ) => T . task . of ( a ) , ( ) => go ( status ) ) ) ) ) ; } else { return T . task . of ( a ) ; } } ) ) ; return go ( defaultRetryStatus ) ; }