Skip to content

Commit

Permalink
Check for _aborted before _fire() (#38)
Browse files Browse the repository at this point in the history
* Check for _aborted before _fire()
  • Loading branch information
mariarek authored and berickson1 committed Sep 21, 2018
1 parent e62c713 commit d2f6ea8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simplerestclients",
"version": "0.2.1",
"version": "0.2.2",
"description": "A library of components for accessing RESTful services with javascript/typescript.",
"author": "David de Regt <David.de.Regt@microsoft.com>",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/SimpleWebRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export abstract class SimpleWebRequestBase<TOptions extends WebRequestOptions =
blockPromise.finally(() => {
_.remove(blockedList, req);
}).then(() => {
if (executingList.length < SimpleWebRequestOptions.MaxSimultaneousRequests) {
if (executingList.length < SimpleWebRequestOptions.MaxSimultaneousRequests && !req._aborted) {
executingList.push(req);
req._fire();
} else {
Expand Down
13 changes: 13 additions & 0 deletions test/SimpleWebRequest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,19 @@ describe('SimpleWebRequest', () => {

blockDefer.reject(errorString);
});

it('does not attempt to fire aborted request, if it was aborted while blocked', () => {
SimpleWebRequestOptions.MaxSimultaneousRequests = 1;
const url = faker.internet.url();
const method = 'GET';
const blockDefer = SyncTasks.Defer<void>();
const requestPromise = new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.Critical }, undefined, () => blockDefer.promise()).start();
requestPromise.cancel();

blockDefer.resolve(void 0);
expect(jasmine.Ajax.requests.count()).toBe(0);

});
});

// @TODO Add more unit tests
Expand Down

0 comments on commit d2f6ea8

Please sign in to comment.