MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / once

Function once

packages/vite/runtime/core-aliases-early.ts:196–227  ·  view source on GitHub ↗
(fn: () => void, timeoutMs = 6000)

Source from the content-addressed store, hash-verified

194 }
195 };
196 const once = (fn: () => void, timeoutMs = 6000) => {
197 try {
198 const a: any = App.android;
199 if (!a || typeof a.on !== 'function' || typeof a.off !== 'function') {
200 // Fallback polling if events API not ready
201 const start = Date.now();
202 const tick = () => {
203 if (isReady() || Date.now() - start > timeoutMs) return fn();
204 setTimeout(tick, 60);
205 };
206 return tick();
207 }
208 let done = false;
209 const finish = () => {
210 if (done) return;
211 done = true;
212 try {
213 a.off(a.activityStartedEvent || 'activityStarted', onAny);
214 a.off(a.activityResumedEvent || 'activityResumed', onAny);
215 } catch {}
216 fn();
217 };
218 const onAny = () => {
219 if (isReady()) finish();
220 };
221 a.on(a.activityStartedEvent || 'activityStarted', onAny);
222 a.on(a.activityResumedEvent || 'activityResumed', onAny);
223 setTimeout(finish, timeoutMs);
224 } catch {
225 fn();
226 }
227 };
228 const patched = function __ns_safe_resetRootView(this: any, entry: any) {
229 if (!isReady()) {
230 if (verbose) {

Callers 1

installCoreAliasesEarlyFunction · 0.85

Calls 3

tickFunction · 0.85
onMethod · 0.65
setTimeoutFunction · 0.50

Tested by

no test coverage detected