export default class CircuitBreakApp {
    async Ping(ping) {
        async function execIfLocal(fn) {
            try {
                await fn();
            }
            catch (err) {
                if (ping.message === 'ClearBreak' &&
                    err instanceof Error &&
                    err.message === 'ServerCallRequired') {
                    // Executing in a local runtime but invocation requires remote. Use
                    // a loading state locally and emit an effect. Continue execution.
                    clearCircuitBreak();
                    return 'Loading';
                }
                // A third error state could be supported too `return 'Error';`.
            }
            return 'Resolved';
        }
        const state = await execIfLocal(async () => await fetch('https://example.com'));
        return { delayMillis: 0, message: state, successProbability: 0 };
    }
}
