diff --git a/README.md b/README.md index 034e44f..3860184 100644 --- a/README.md +++ b/README.md @@ -127,8 +127,10 @@ import { retry } from "@mrspartak/promises" import { apiCall } from "./api" // Retry the API call up to 3 times with a delay of 1000 milliseconds between attempts -const result = await retry(() => apiCall(), 3, { delay: 1000 }) -console.log(result) +const [error, result] = await retry(() => apiCall(), 3, { delay: 1000 }) +if (error) { + // error will always be an error returneb by a promise rejection +} ``` ### `duration` - Measure the Time Taken for a Promise to Resolve diff --git a/docs/assets/navigation.js b/docs/assets/navigation.js index 91a171b..ccfbb48 100644 --- a/docs/assets/navigation.js +++ b/docs/assets/navigation.js @@ -1 +1 @@ -window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAACp2UXUvDMBSG/0uuN+emmzhEED9AECbi3Rgja85YWJqUk1O1iP/drHZrO0NSdtvzPs/LgZPOvxnBF7Epu5GaADVXt6zHMk4b9y01IldgB8v9bHm2oVS5wFZqwaajHks2UgkEzabzg+oR0WBtKeE1T9qiMnSkG0+cUHFrHUVW9KXtO2MJsJ9e239vtCXME+pY1cif1vqKJpUWXuQWYoWN6Gldd59cEoi6h4qsXVEljvTn11fD8ahTxQOsARHELKdATSPlrWoKc+QkjY4I61RM+AaExSzbpW3A2IzFlO8yBZPTsw74DpmOsvC+dSiqM0/SIaoI2faZuCy8o+mwnolsZjosdfQr+OAo+Up5nmd/2FZdhK540WgQ1YXWJetcJ+U1DPaztnpy2cIVL/ysG4TA6pC9bDUL4Li7Wh9bDgKgVQCZDywHAZD+LtGHVqMQbLyc+YcsfgF1y9FMUgYAAA==" \ No newline at end of file +window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAACp2UXUvDMBSG/0uuN6fTTRwiiB8gCBPxbowRmzMWliYlOVWL+N/Naru2M5yU3fa8z/PmQNLFN0P4QjZj11IjWM3VDRuwjOPGf0uNyBW40aqerU42mCof2Eot2Gw8YMlGKmFBs9lir3qw1tjGUsJrnnRFZehAN5l6oeLOeQqdGEo39MYSYD+Drv/OaIc2T7BnVSt/XOuLNal08Cy3ECtsRY/ruv3kEkE0PVhk3YoqcaA/vbo8m4x7VdzDGqwFMc+RqGmlglVtYW45SqMjwiYVE74C2mKe7dKOMLZj/ZTkAetITPUmUzA5PmnCtc/0lNEna0JRnXmUHlEFZaszcRm9o+mxnolsZnosdfBX+eBW8ncVeOnDs67qnHoQy1aDqC57U7LOdVJerFE966qnFx1c8SLM+gEFVm8iyFYzAre7GxtiywEBOgWQhcByQID4dxNDaDWiYBPkzD9k+Qum5QLynQYAAA==" \ No newline at end of file diff --git a/docs/assets/search.js b/docs/assets/search.js index ce70120..00bad9e 100644 --- a/docs/assets/search.js +++ b/docs/assets/search.js @@ -1 +1 @@ -window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAACs1Yy4rbMBT9F3XrenLlR5xQuiqFWQ2U0o0JIUwUxq1f2M60Q8i/V7JlSzcjOXY6A10lss65r3N1I+dEquJ3TdbxifxK8j1Zh75D8l3GyJo0BXHIsUr518Mxf2ySIq/vmsJ9arKU7zymu7pmnEvI2THQ9yzdvRgstM+nGqlTxkqDkfb5VCNNkrHi2Jiy6Xamp3RgVcX2xqy6rammKtZUpuq0zyfHc6x2gmaKR26NmqKDpU9J3rAq36WfB1tZsT+mrL7b9lvbcVuL1RICZfF7ca/ial5KbEnsGsw5pNxVLG9wRGNOviYckr6MeZKQG9yFQeCFg7PtVhif6unDAL/mUBFHM33QOtjg+8HYxrML2h2IUel6yNu5G09twLyBwy/ymI561EDv3jSXvma0jZ6Lcg8LqgZEWRVZUs937yrinDBcGbwlmorVRfp8QzSK+G/RvIk0fTTS/EfvtrCGpKzF+skeZzSpik7y/o9SiWD6SsHNlWpTsp/qb+JH86Fsf/nsQeqodz/Xr5zNONgoHUt74NvVZPduz5sVxOv2eDVX5XVjfK4q0PT6bxzCPbI/ZH0iz6yqxXVnTajruStOOSQs3Yv7axcIN1hkmTCykXs/eOcUlUB0kLsFceKFQyM3oOFm48Q9o91oH7Qw3qsxONRzfYgQDBCM8hU1WaMIxmdE7JlgHoL5fOWbYD6CBXwVmGABgoV8FZpgIYIt+Wppgi0RLOKryASLEIyLEq9MsBUur6g2LBwI3MDzcIEvhGiVAJNJwFqAqDkY1QAsB4iyg1EQwIqAqDwYNQEsCgT2jLAuIOoPRgEBSwNCAjBqCFgdiOzesUAghACj4IA1onaNKNaIthoZu4NenBdqt4k1op7tBFIsEW0lMvYc7SRqRwifHQ3b33ejhA+DfhyfyFbOFx6WHGcnwptwfTo7hEvXfUbdJ5XPebD886zmjVgJ1+oVURn2lV3/Cq19TdVC0qhg57YjXWNpJBmuZ+MOb5CKHip6eIV2Ge5KUakt3H6268Sl4i0ttOFGqrkLtERtofb3IY2meeMtb6PJK6fG0woDtjDle71iaTEGY5yiv75oDiOtnGAhy39IFItqJAtn+ENEsTzFsvWKZCWoWUBzB1f8XXaL5hOsTgudop3QhZVw6P8SUDytL22CNwVOTKt9ZKVcZqSfPKNgfBSVScnSJOegeHM+/wWgRKSRgRMAAA=="; \ No newline at end of file +window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAACs1YTY+bMBD9L+6VshkTCERVT1WlPa1UVb1EURRtHJWWQARk21WU/14bDPZkx4SkqdRTAn5vvt54MBxZWfyq2HxxZD/TfMPm0dRj+Xon2JzVBfPYoczk3+0hf67TIq8e6sL/Xu8yufKcratKSC5jJ4+gb0S2fiUsNPfHGqkyIfaEkeb+WCN1uhPFoaayaVfGp7QVZSk2ZFbt0lhTpahLqjrN/dHxHMq1olHx6KVBU7y39CHNa1Hm6+xjb2tXbA6ZqB5W3dJq2NYkmUFoLH4tHk1c9eseW1KrhDmP7delyGsc0ZCTz6mEZK9DnjTkBndRGAZR72y1UsbHenrXwy85NMTBTJ+sDiZ8P5FtfHVB2w0xKF0HuZ+74dR6zB0cftLbdNCjBfrnTXPu64q2sXMx7mHCzYDYl8Uura537xviNWH4OnhHNKWoiuzlhmgM8e+iuYs0XTTa/PvgtrD6pJzF+iGer2hSE53m/R+lUsF0lYKbK9Wk5N7VX9RD82nfPPncQdqof76v3zi7YmOjdBztgU9Xo937He+qIN62B63A0FDtEPcY4vpsMzzEDWi8y6XHpEfxm82P7EWUlTpbzRn3Az+RlG0qso06LLeBSIPFbqeMLPXaN9mmRakQLeRhwrzFxOOxn0ymy6W36BjNQnOjgcmNsQCPB/4sCREMEIzLK05Z4wgmB9IioGABgk3l1ZSCTREslFchBQsRLJJXEQWLEGwmr2YUbIZgsbyKKViMYFKURULBElxeVW2YeBD6CQAu8JkQjRJAmQSsBaiaA6kGYDlAlR1IQQArAqryQGoCWBQI3RlhXUDVH0gBAUsDSgIgNQSsDsRu71ggUEIAKThgjbhbI4414o1GZHfws/3C3TaxRjxw7UCOJeKNRGTPcSwRVzpwcvPzVqJm2MgpU4vNYzt05NjonhJHttKTSCagB9+RyXadH08ekyK3v3H7y/V9mZb8PZnJpK6Ua/PmagxPjd3pBVrz9myFZFHBzW2eNBbLIulwAxe3f7E19MjQowu0s3C5VUEeOrjdU8Amzgxv5qD1B2Urz9BK1BVqd0yzaJY3uTlcNH0StnhWYcAVpv7cYFhWjK6KNJyiO1VZDmOrnDBIPmubxCK62kZ/8bHUs0gOTv+Bx7ACw3I1mWalqMvAcgcX/J2nZ/kEp9PCpliNOXEStt0nDsOzCunqlLrAiVmixU7KeUb2liWVljNsn+5FluYStFieTn8AAHqCClEUAAA="; \ No newline at end of file diff --git a/docs/coverage.svg b/docs/coverage.svg index 80b4364..3044ac9 100644 --- a/docs/coverage.svg +++ b/docs/coverage.svg @@ -11,7 +11,7 @@ document document - 78% - 78% + 80% + 80% \ No newline at end of file diff --git a/docs/functions/deferred.html b/docs/functions/deferred.html index 3868fa6..1e1eca7 100644 --- a/docs/functions/deferred.html +++ b/docs/functions/deferred.html @@ -161,7 +161,7 @@

Type Parameters

Returns DeferredOut<T>

An object containing the promise, resolve, and reject functions.

-
  • Retries a promise-returning function a specified number of times with an optional delay between attempts if it fails.

    -

    Example


    import { retry } from "@mrspartak/promises"
    import { apiCall } from "./api"

    // Retry the API call up to 3 times with a delay of 1000 milliseconds between attempts
    const result = await retry(() => apiCall(), 3, { delay: 1000 })
    console.log(result) +
    • Retries a promise-returning function a specified number of times with an optional delay between attempts if it fails.

      +

      Example


      import { retry } from "@mrspartak/promises"
      import { apiCall } from "./api"

      // Retry the API call up to 3 times with a delay of 1000 milliseconds between attempts
      const [error, result] = await retry(() => apiCall(), 3, { delay: 1000 })
      if (error) {
      // error will always be an error returneb by a promise rejection
      }

      Type Parameters

      • T

        The type of the value that the promise resolves to.

      Parameters

      • fn: (() => Promise<T>)

        The promise-returning function to be retried.

          • (): Promise<T>
          • Returns Promise<T>

      • attempts: number

        The number of retry attempts. Must be a positive integer.

      • Optional options: RetryOptions

        Optional settings for retry behavior.

        -

      Returns Promise<T>

      The resolved value of the promise.

      -

      Throws

      Throws an error if all retry attempts fail.

      -
    DeferredOut<T>: {
        promise: Promise<T>;
        reject: ((reason?) => void);
        resolve: ((value) => void);
    }

    Represents a deferred promise, which exposes the resolve and reject functions.

    Type Parameters

    • T

      The type of the value that the promise resolves to.

      -

    Type declaration

    • promise: Promise<T>
    • reject: ((reason?) => void)
        • (reason?): void
        • Parameters

          • Optional reason: any

          Returns void

    • resolve: ((value) => void)
    DurationOut<T>: [Error, null, number] | [null, T, number]

    Type representing the output of the duration function. The result is a tuple that includes either an error or a value, and the duration in milliseconds.

    Type Parameters

    • T

      The type of the resolved value of the promise.

      -
    RetryOptions: {
        delay?: number;
    }

    Options for the retry function.

    -

    Type declaration

    • Optional delay?: number
    RetryOut<T>: [Error, null] | [null, T]

    Type representing the output of the retry function. +The result is a tuple that includes either an error or a value, and the duration in milliseconds.

    +

    Type Parameters

    • T

      The type of the resolved value of the promise.

      +
    \ No newline at end of file diff --git a/docs/types/_internal_.TimeoutIn.html b/docs/types/_internal_.TimeoutIn.html index 16fc6f4..8660892 100644 --- a/docs/types/_internal_.TimeoutIn.html +++ b/docs/types/_internal_.TimeoutIn.html @@ -157,7 +157,7 @@ --md-sys-color-surface-container-highest: #e4e1e6 }
    TimeoutIn<T>: Promise<T>

    Type alias for a promise of type T.

    -

    Type Parameters

    • T
    TimeoutOut<T>: [Error, null] | [null, T]

    Return type for the timeout function.

    -

    Type Parameters

    • T
    ToFinally: (() => void | Promise<void>)

    Type alias for a function that can optionally be executed after the promise resolves or rejects. It can return void or a Promise that resolves to void.

    -

    Type declaration

      • (): void | Promise<void>
      • Returns void | Promise<void>

    ToIn<T>: Promise<T>

    Type alias for a promise of type T.

    -

    Type Parameters

    • T
    ToOut<T>: [Error, null] | [null, T]

    Type alias for the output of the to function. It can be either an array with an Error and null, or an array with null and the result of type T.

    -

    Type Parameters

    • T