Skip to content

Commit

Permalink
Abortable Fetch Requests + Fetch Request Queue
Browse files Browse the repository at this point in the history
- Renamed directory `lib` to `src` to better represent the source files
- fetch_provider.js:
  - Added `maxConcurrency` option, defaults to 5 concurrent requests
  - Added internal vars and helps to aid in the concurrent queue
  - execute() now queues all requests by default, and executes then when able to do so
  - Added provider.areRequestsSaturated() to check if concurrency is maxed out
  - Added signal handling, so fetch requests can be aborted
- query.js: Added options property and setOptions fluent helper (used only by fetch provider atm)
- tests: Updated for proof of coverage of new features
- gulpfile.js: Updated for src rename
- package.json: Added dev dependency abort-controller and updated node-fetch dep to work with signals
- README.md: updated docs
  • Loading branch information
kfitzgerald committed Oct 2, 2019
1 parent 9a5d2fe commit da39f05
Show file tree
Hide file tree
Showing 21 changed files with 2,153 additions and 1,578 deletions.
37 changes: 37 additions & 0 deletions README.md
Expand Up @@ -85,4 +85,41 @@ With await:
const res = await api.sessions.create(payload).execute();
```

## Aborting requests

When using the FetchProvider, you can provide a controller signal to shutdown a fetch request.

For example:

```js

const controller = new AbortController();
const signal = controller.signal;

api.organizations.list({}).setOptions({ signal }).execute()
.then(res => {
// res completed successfully
// (this won't fire in this example)
})
.catch(err => {
// request failed or was aborted
// in this example, err looks like this:
/*
err = {
statusCode: 503,
error: 'The user aborted a request.',
message: 'Something went wrong'
}
*/
})
;

// Abort the request
setTimeout(() => {
controller.abort();
}, 100);


```

See the [Okanjo API documentation](https://developer.okanjo.com/api) for information on what routes are available for use.
12 changes: 6 additions & 6 deletions dist/client.js
Expand Up @@ -35,8 +35,8 @@
* SOFTWARE.
*/

var Provider = require('../lib/provider'),
Query = require('../lib/query');
var Provider = require('../src/provider'),
Query = require('../src/query');

/**
* SDK Base
Expand Down Expand Up @@ -65,11 +65,11 @@ function Client(config) {
// Detect context
if (process.browser) {
// Running in browser - default to proxy mode
//this.provider = new (require('../lib/providers/jquery_provider'))(this);
this.provider = new (require('../lib/providers/fetch_provider'))(this);
//this.provider = new (require('../src/providers/jquery_provider'))(this);
this.provider = new (require('../src/providers/fetch_provider'))(this);
} else {
// Running in Node - Use the HTTP provider by default to make real requests
this.provider = new (require('../lib/providers/http_provider'))(this);
this.provider = new (require('../src/providers/http_provider'))(this);
}
}

Expand All @@ -82,7 +82,7 @@ function Client(config) {
/**
* SDK Version
*/
Client.Version = '2.6.0';
Client.Version = '3.0.0';

/**
* Expose the Provider base class
Expand Down

0 comments on commit da39f05

Please sign in to comment.