# retry-until-online

> Delay the execution of a function until the browser is back online

Latest version **3.0.2** (published 2018-05-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install retry-until-online
pnpm add retry-until-online
yarn add retry-until-online
bun add retry-until-online
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2018-05-20 |
| First published | 2016-09-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 170.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Markus Oberlehner |
| Maintainers | maoberlehner |
| Keywords | offline first |

## Links

- npm: https://www.npmjs.com/package/retry-until-online
- Repository: https://github.com/maoberlehner/retry-until-online
- Issues: https://github.com/maoberlehner/retry-until-online/issues
- npm.io page: https://npm.io/package/retry-until-online

## Recent versions

- 3.0.2 (latest) — 2018-05-20
- 3.0.1 — 2018-04-13
- 3.0.0 — 2018-04-05
- 2.0.1 — 2017-11-23
- 2.0.0 — 2017-11-01
- 1.1.3 — 2017-08-11
- 1.1.2 — 2017-08-08
- 1.1.1 — 2017-08-04
- 1.1.0 — 2017-08-03
- 1.0.2 — 2017-07-04
- 1.0.1 — 2017-06-06
- 1.0.0 — 2017-02-02
- 0.1.5 — 2016-10-14
- 0.1.4 — 2016-10-01
- 0.1.3 — 2016-10-01
- … 4 more at https://npm.io/package/retry-until-online/versions

## README

# retry-until-online

[![Patreon](https://img.shields.io/badge/patreon-donate-blue.svg)](https://www.patreon.com/maoberlehner)
[![Donate](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://paypal.me/maoberlehner)
[![Build Status](https://travis-ci.org/maoberlehner/retry-until-online.svg?branch=master)](https://travis-ci.org/maoberlehner/retry-until-online)
[![Coverage Status](https://coveralls.io/repos/github/maoberlehner/retry-until-online/badge.svg?branch=master)](https://coveralls.io/github/maoberlehner/retry-until-online?branch=master)
[![GitHub stars](https://img.shields.io/github/stars/maoberlehner/retry-until-online.svg?style=social&label=Star)](https://github.com/maoberlehner/retry-until-online)

Delay the execution of a function until the browser is back online.

Imagine a user is traveling by train and browsing your webshop on his phone. He finds what he is looking for and taps the "Buy now" button. But suddenly: a tunnel. The connection is lost and the AJAX request (for putting the product in the cart) fails.

By wrapping AJAX requests with the `retryUntilOnline` function you can prevent failing AJAX requests. Like in the tunnel example, the connection may be only lost for some seconds `retryUntilOnline` will execute the AJAX request as soon as the connection is restored.

## Usage

```bash
# Install the module.
npm install retry-until-online --save
```

```js
// Load the module.
import retryUntilOnline from 'retry-until-online';

// Delay the execution of a jQuery AJAX request until the browser is back online.
retryUntilOnline({ callback: () => $.ajax({ url: 'test.html' }) })
  .then((value) => {
    // This is called after the callback function was called,
    // `value` is the return value of the callback function.
  })
  .catch((value) => {
    // This is called when `maxTries` is reached and the offline
    // callback function was called, `value` is the return value
    // of the offline callback function.
  });
```

### Options

```js
import retryUntilOnline from 'retry-until-online';

const options = {
  callback: () => undefined, // Callback function which is called if online.
  offlineCallback: () => undefined, // Callback function that is executed if `tries` reaches 0.
  interval: 500, // Interval for checking the online status.
  maxTries: -1, // How often the online status should be checked before giving up (-1 = unlimited).
};

retryUntilOnline(options);
```

## About

### Author

Markus Oberlehner  
Website: https://markus.oberlehner.net  
Twitter: https://twitter.com/MaOberlehner  
PayPal.me: https://paypal.me/maoberlehner  
Patreon: https://www.patreon.com/maoberlehner

### License

MIT

---
_Source: https://npm.io/package/retry-until-online · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
