mirror of
https://github.com/logos-storage/logos-storage-js.git
synced 2026-01-03 22:13:07 +00:00
20 lines
508 B
TypeScript
20 lines
508 B
TypeScript
import { CodexError } from "../async";
|
|
import type { SafeValue } from "../values/values";
|
|
|
|
export const Promises = {
|
|
async safe<T>(promise: () => Promise<T>): Promise<SafeValue<T>> {
|
|
try {
|
|
const result = await promise();
|
|
|
|
return { error: false, data: result };
|
|
} catch (e) {
|
|
return {
|
|
error: true,
|
|
data: new CodexError(e instanceof Error ? e.message : "" + e, {
|
|
sourceStack: e instanceof Error ? e.stack || null : null,
|
|
}),
|
|
};
|
|
}
|
|
},
|
|
};
|