MCPcopy Create free account
hub / github.com/arktypeio/arktype / settle

Function settle

ark/type/deferred.ts:120–163  ·  view source on GitHub ↗
(self: BaseRoot, d: Deferred)

Source from the content-addressed store, hash-verified

118let settling = 0
119
120const settle = (self: BaseRoot, d: Deferred): BaseRoot => {
121 if (d.target) return d.target
122 const prior = lastCreated
123 settling++
124 let node: BaseRoot
125 try {
126 node = d.resolve!()
127 } finally {
128 settling--
129 }
130 const created = lastCreated
131 d.resolve = undefined
132 if (!Object.isExtensible(self)) {
133 const materialized = node.$.fin(node)
134 d.target = materialized
135 const cache = d.c as { self: BaseRoot; rootApply?: Function }
136 cache.self = materialized
137 cache.rootApply = (data: unknown, onFail?: unknown) =>
138 (materialized as any)(data, undefined, onFail)
139 if (d.$.nodesByKey.get(d.facts.key) === self)
140 d.$.nodesByKey.set(d.facts.key, materialized)
141 return materialized
142 }
143 createNode({
144 id: node.id,
145 kind: node.kind,
146 inner: node.inner,
147 meta: node.meta,
148 $: node.$,
149 ignoreCache: true,
150 shell: d
151 })
152 const key = node.c.key
153 self.c.key = key
154 // what holds `this` prints it, which its nodes written again wouldn't
155 if (Object.getOwnPropertyDescriptor(node, "expression")?.get)
156 printSelfAsThis(self, node)
157 // no other holds a node it just created, so what reaches its key next is this
158 if (key && node.id === created && created !== prior) {
159 node.$.nodesByKey.set(key, self)
160 if ($ark.nodesById.get(node.id) === node) $ark.nodesById.set(node.id, self)
161 }
162 return node.$.fin(self)
163}
164
165const settled = (self: any): any => {
166 const d = deferred.get(self)

Callers 1

settledFunction · 0.70

Calls 5

createNodeFunction · 0.90
printSelfAsThisFunction · 0.90
getMethod · 0.65
finMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected