Skip to content

Commit

Permalink
Merge branch 'master' into Implementation_change
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Dedys authored and Mike Dedys committed Oct 7, 2015
2 parents 76224f8 + c69e66c commit ab6c402
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,50 @@

[![NPM version][npm-image]][npm-url]
[![Build status][ci-image]][ci-url]
[![Coverage Status](https://coveralls.io/repos/Brightspace/superagent-d2l-promise-queue/badge.svg?branch=master&service=github)](https://coveralls.io/github/Brightspace/superagent-d2l-promise-queue?branch=master)
[![Coverage Status](https://coveralls.io/repos/Brightspace/superagent-d2l-queue/badge.svg?branch=master&service=github)](https://coveralls.io/github/Brightspace/superagent-d2l-queue?branch=master)

Request queue that uses Q promise library and superagent.
Extends Superagent by adding the ability to queue up requests and retry failed requests due to timeouts.

## Installation

Install from NPM:

```shell
npm install superagent-d2l-promise-queue
npm install superagent-d2l-queue
```

Uses the superagent library to perform ajax requests. Returns a deferred promises using the Q library.

## Usage

`send( Object )`
Added functions:

The send function returns a deferred promise which can be resolved or rejected. The promise will be rejected if the request returns a error code such as 400, 404, 500, etc. The queue will attempt to retry the requst every 2 seconds if the request did not recieve a response from the endpoint provided. Before a retry the deferred object will send a `.notify` which can be subscribed to using `.progress` on the client side to preform any action prior to retry such as notifying the user that a connection loss occured.
`useQueue()`

```js
import Request from 'superagent-d2l-promise-queue';

Request.send(
{
url: someUrl,
method: 'POST',
payload: { text: 'Creating some entity' },
useQueue: true,
auth: sessionAuth
}
);
```
Every request that has this specified will be queued up.

`retryOnConnectionFailure( handler )`

**payload**, **useQueue** and **auth** are optional parameters.
When a request fails due to a timeout or connection failure the request will be retried every 2 seconds until it can successfully send the request. A hanlder function can be specified in order to complete some action whenever a timeout occurs. This handler is optional.

```js
Request.send(
{
url: someUrl,
method: 'GET'
}
);
import Request from 'superagent';
import 'superagent-d2l-queue';

Request
.get( '/me' )
.useQueue()
.retryOnConnectionFailure( function() {
//do something
})
.end( function( err,res ) {
//do something
});
```
[npm-url]: https://npmjs.org/package/superagent-d2l-promise-queue
[npm-image]: https://badge.fury.io/js/superagent-d2l-promise-queue.png
[ci-url]: https://travis-ci.org/Brightspace/superagent-d2l-promise-queue
[ci-image]: https://travis-ci.org/Brightspace/superagent-d2l-promise-queue.svg


[npm-url]: https://npmjs.org/package/superagent-d2l-queue
[npm-image]: https://badge.fury.io/js/superagent-d2l-queue.png
[ci-url]: https://travis-ci.org/Brightspace/superagent-d2l-queue
[ci-image]: https://travis-ci.org/Brightspace/superagent-d2l-queue.svg

0 comments on commit ab6c402

Please sign in to comment.