on-error-resume-next
Version:
Run a function, synchronously or asynchronously, and ignore errors.
1 lines • 1.34 kB
Source Map (JSON)
{"version":3,"sources":["../src/index.auto.ts"],"sourcesContent":["import isPromise from './private/isPromise.ts';\n\nexport function onErrorResumeNext<T extends () => U, U = unknown>(fn: T, context?: undefined): U | undefined;\nexport function onErrorResumeNext<T extends (this: V) => U, U = unknown, V = undefined>(\n fn: T,\n context: V\n): U | undefined;\n\nexport function onErrorResumeNext<T extends () => Promise<U>, U = unknown>(\n fn: T,\n context?: undefined\n): Promise<U | undefined>;\n\nexport function onErrorResumeNext<T extends (this: V) => Promise<U>, U = unknown, V = undefined>(\n fn: T,\n context: V\n): Promise<U | undefined>;\n\nexport function onErrorResumeNext<T extends (this: V) => U | Promise<U>, U = unknown, V = undefined>(\n fn: T,\n context: V\n): U | undefined | Promise<U | undefined> {\n try {\n const result = fn.call(context);\n\n if (isPromise(result)) {\n return new Promise<U | undefined>(resolve => result.then(resolve, () => resolve(undefined)));\n }\n\n return result;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;AAkBO,SAAS,kBACd,IACA,SACwC;AACxC,MAAI;AACF,UAAM,SAAS,GAAG,KAAK,OAAO;AAE9B,QAAI,UAAU,MAAM,GAAG;AACrB,aAAO,IAAI,QAAuB,aAAW,OAAO,KAAK,SAAS,MAAM,QAAQ,MAAS,CAAC,CAAC;AAAA,IAC7F;AAEA,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}