Files
image-workbench-desktop/src/runtime-boundary.js
T

23 lines
1020 B
JavaScript

;(function (global) {
'use strict'
function safeInvoke(fn, fallback, report) {
try { return typeof fn === 'function' ? fn() : fallback } catch (error) { if (typeof report === 'function') report(error); return fallback }
}
function safeAsync(fn, fallback, report) {
let value
try { value = typeof fn === 'function' ? fn() : fallback } catch (error) { if (typeof report === 'function') report(error); return Promise.resolve(fallback) }
return Promise.resolve(value).catch((error) => { if (typeof report === 'function') report(error); return fallback })
}
function create(options) {
const opt = options || {}
const report = typeof opt.report === 'function' ? opt.report : function () {}
return {
invoke(fn, fallback) { return safeInvoke(fn, fallback, report) },
async(fn, fallback) { return safeAsync(fn, fallback, report) },
report,
}
}
global.IWBRuntimeBoundary = { safeInvoke, safeAsync, create }
})(typeof window !== 'undefined' ? window : globalThis)