MCPcopy
hub / github.com/supermacro/neverthrow / safeTry

Function safeTry

src/result.ts:122–132  ·  view source on GitHub ↗
(
  body:
    | (() => Generator<Err<never, E>, Result<T, E>>)
    | (() => AsyncGenerator<Err<never, E>, Result<T, E>>),
)

Source from the content-addressed store, hash-verified

120 InferErrTypes<YieldErr> | InferErrTypes<GeneratorReturnResult>
121>
122export function safeTry<T, E>(
123 body:
124 | (() => Generator<Err<never, E>, Result<T, E>>)
125 | (() => AsyncGenerator<Err<never, E>, Result<T, E>>),
126): Result<T, E> | ResultAsync<T, E> {
127 const n = body().next()
128 if (n instanceof Promise) {
129 return new ResultAsync(n.then((r) => r.value))
130 }
131 return n.value
132}
133
134interface IResult<T, E> {
135 /**

Callers 4

safe-try.test.tsFile · 0.90
myFuncFunction · 0.90
fnFunction · 0.90
typecheck-tests.tsFile · 0.90

Calls 1

thenMethod · 0.80

Tested by 2

myFuncFunction · 0.72
fnFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…