MCPcopy Create free account
hub / github.com/hoothin/UserScripts / safelyResolveThenable

Function safelyResolveThenable

Picviewer CE+/dist.user.js:4691–4718  ·  view source on GitHub ↗
(self, thenable)

Source from the content-addressed store, hash-verified

4689}
4690
4691function safelyResolveThenable(self, thenable) {
4692 // Either fulfill, reject or reject with error
4693 var called = false;
4694 function onError(value) {
4695 if (called) {
4696 return;
4697 }
4698 called = true;
4699 handlers.reject(self, value);
4700 }
4701
4702 function onSuccess(value) {
4703 if (called) {
4704 return;
4705 }
4706 called = true;
4707 handlers.resolve(self, value);
4708 }
4709
4710 function tryToUnwrap() {
4711 thenable(onSuccess, onError);
4712 }
4713
4714 var result = tryCatch(tryToUnwrap);
4715 if (result.status === 'error') {
4716 onError(result.value);
4717 }
4718}
4719
4720function tryCatch(func, value) {
4721 var out = {};

Callers 2

PromiseFunction · 0.70
dist.user.jsFile · 0.70

Calls 2

tryCatchFunction · 0.70
onErrorFunction · 0.70

Tested by

no test coverage detected