tio.js
Version:
Evaluate code in a sandboxed environment everywhere with TryItOnline.
35 lines • 1.07 kB
JavaScript
import { TioHttpError } from './error.js';
export function validStringArray(arr) {
return (Array.isArray(arr) &&
arr.every(elem => typeof elem === 'string' && elem.length));
}
export async function request(path, options) {
const response = await fetch(`https://tio.run${path}`, options);
/* node:coverage ignore next 3 */
if (!response.ok) {
throw new TioHttpError(response);
}
return response;
}
export class Timeout {
#timeout;
promise;
constructor(ab, tm) {
this.#timeout = null;
this.promise = new Promise(resolve => {
ab.signal.addEventListener('abort', () => {
if (this.#timeout !== null) {
clearTimeout(this.#timeout);
this.#timeout = null;
}
resolve(null);
});
if (tm && tm !== Infinity) {
this.#timeout = setTimeout(() => {
resolve(null);
}, tm);
}
});
}
}
//# sourceMappingURL=util.js.map