MCPcopy
hub / github.com/Effect-TS/effect / fromRequest

Function fromRequest

packages/effect/src/internal/query.ts:41–143  ·  view source on GitHub ↗
(
  request: A,
  dataSource: Ds
)

Source from the content-addressed store, hash-verified

39
40/** @internal */
41export const fromRequest = <
42 A extends Request.Request<any, any>,
43 Ds extends
44 | RequestResolver.RequestResolver<A>
45 | Effect.Effect<RequestResolver.RequestResolver<A>, any, any>
46>(
47 request: A,
48 dataSource: Ds
49): Effect.Effect<
50 Request.Request.Success<A>,
51 Request.Request.Error<A>,
52 [Ds] extends [Effect.Effect<any, any, any>] ? Effect.Effect.Context<Ds> : never
53> =>
54 core.flatMap(
55 (core.isEffect(dataSource) ? dataSource : core.succeed(dataSource)) as Effect.Effect<
56 RequestResolver.RequestResolver<A>
57 >,
58 (ds) =>
59 core.fiberIdWith((id) => {
60 const proxy = new Proxy(request, {})
61 return core.fiberRefGetWith(currentCacheEnabled, (cacheEnabled) => {
62 if (cacheEnabled) {
63 const cached: Effect.Effect<any, any> = core.fiberRefGetWith(currentCache, (cache) =>
64 core.flatMap(cache.getEither(proxy), (orNew) => {
65 switch (orNew._tag) {
66 case "Left": {
67 if (orNew.left.listeners.interrupted) {
68 return core.flatMap(
69 cache.invalidateWhen(proxy, (entry) => entry.handle === orNew.left.handle),
70 () => cached
71 )
72 }
73 orNew.left.listeners.increment()
74 return core.uninterruptibleMask((restore) =>
75 core.flatMap(
76 core.exit(core.blocked(
77 BlockedRequests.empty,
78 restore(core.deferredAwait(orNew.left.handle))
79 )),
80 (exit) => {
81 orNew.left.listeners.decrement()
82 return exit
83 }
84 )
85 )
86 }
87 case "Right": {
88 orNew.right.listeners.increment()
89 return core.uninterruptibleMask((restore) =>
90 core.flatMap(
91 core.exit(
92 core.blocked(
93 BlockedRequests.single(
94 ds as RequestResolver.RequestResolver<A>,
95 BlockedRequests.makeEntry({
96 request: proxy,
97 result: orNew.right.handle,
98 listeners: orNew.right.listeners,

Callers

nothing calls this directly

Calls 9

incrementMethod · 0.95
decrementMethod · 0.95
restoreFunction · 0.85
syncMethod · 0.80
getEitherMethod · 0.65
invalidateWhenMethod · 0.65
incrementMethod · 0.65
decrementMethod · 0.65
singleMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…