fix: #1075 Returning to the Study List before all series have finishe… (#1090)

* fix: #1075 Returning to the Study List before all series have finished loading throws multiple errors in console

* fix: 🐛 Addressing review feedback from issue #1075

Adding support for cancelable pattern

Closes: #1075

* fix: 🐛 update unit test for exports

Closes: #1075
This commit is contained in:
Emanuel Fiuza de Oliveira authored and GitHub committed 2019-11-05 16:47:54 -03:00
1 parent d26adf92bd
commit ecaf578f92
5 files changed
+77 -6

No files matched your search

+3
View File
@@ -11,6 +11,7 @@ import writeScript from './writeScript.js';
import DicomLoaderService from './dicomLoaderService.js';
import b64toBlob from './b64toBlob.js';
import * as urlUtil from './urlUtil';
import makeCancelable from './makeCancelable';
const utils = {
guid,
@@ -27,6 +28,7 @@ const utils = {
DICOMTagDescriptions,
DicomLoaderService,
urlUtil,
makeCancelable,
};
export {
@@ -44,6 +46,7 @@ export {
DICOMTagDescriptions,
DicomLoaderService,
urlUtil,
makeCancelable,
};
export default utils;
+1
View File
@@ -17,6 +17,7 @@ describe('Top level exports', () => {
'DICOMTagDescriptions',
'DicomLoaderService',
'urlUtil',
'makeCancelable',
].sort();
const exports = Object.keys(utils.default).sort();
+19
View File
@@ -0,0 +1,19 @@
export default function makeCancelable(thenable) {
let isCanceled = false;
const promise = Promise.resolve(thenable).then(
function(result) {
if (isCanceled) throw Object.freeze({ isCanceled });
return result;
},
function(error) {
if (isCanceled) throw Object.freeze({ isCanceled, error });
throw error;
}
);
return Object.assign(Object.create(promise), {
then: promise.then.bind(promise),
cancel() {
isCanceled = true;
},
});
}