MCPcopy Create free account
hub / github.com/Effect-TS/effect / pickInternalCall

Function pickInternalCall

packages/effect/src/Utils.ts:193–219  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

191// statements) so the whole selection is pure-annotated by the build and
192// tree-shakable when `internalCall` is unused.
193const pickInternalCall = (): <A>(body: () => A) => A => {
194 const InternalTypeId = "~effect/Utils/internal"
195
196 const standard = {
197 [InternalTypeId]: <A>(body: () => A) => {
198 return body()
199 }
200 }
201
202 const forced = {
203 [InternalTypeId]: <A>(body: () => A) => {
204 try {
205 return body()
206 } finally {
207 //
208 }
209 }
210 }
211
212 const limit = getStackTraceLimit()
213 if (limit === 0) return forced[InternalTypeId]
214 // Only the callback and internal call frames are needed for detection.
215 setStackTraceLimit(2)
216 const error = standard[InternalTypeId](() => new Error())
217 setStackTraceLimit(limit)
218 return error.stack?.includes(InternalTypeId) === true ? standard[InternalTypeId] : forced[InternalTypeId]
219}
220
221/** @internal */
222export const internalCall = pickInternalCall()

Callers 1

Utils.tsFile · 0.85

Calls 3

getStackTraceLimitFunction · 0.90
setStackTraceLimitFunction · 0.90
bodyFunction · 0.50

Tested by

no test coverage detected