MCPcopy
hub / github.com/single-spa/single-spa / reasonableTime

Function reasonableTime

src/applications/timeouts.js:108–163  ·  view source on GitHub ↗
(appOrParcel, lifecycle)

Source from the content-addressed store, hash-verified

106}
107
108export function reasonableTime(appOrParcel, lifecycle) {
109 const timeoutConfig = appOrParcel.timeouts[lifecycle];
110 const warningPeriod = timeoutConfig.warningMillis;
111 const type = objectType(appOrParcel);
112
113 return new Promise((resolve, reject) => {
114 let finished = false;
115 let errored = false;
116
117 appOrParcel[lifecycle](getProps(appOrParcel))
118 .then((val) => {
119 finished = true;
120 resolve(val);
121 })
122 .catch((val) => {
123 finished = true;
124 reject(val);
125 });
126
127 setTimeout(() => maybeTimingOut(1), warningPeriod);
128 setTimeout(() => maybeTimingOut(true), timeoutConfig.millis);
129
130 const errMsg = formatErrorMessage(
131 31,
132 __DEV__ &&
133 `Lifecycle function ${lifecycle} for ${type} ${toName(
134 appOrParcel
135 )} lifecycle did not resolve or reject for ${timeoutConfig.millis} ms.`,
136 lifecycle,
137 type,
138 toName(appOrParcel),
139 timeoutConfig.millis
140 );
141
142 function maybeTimingOut(shouldError) {
143 if (!finished) {
144 if (shouldError === true) {
145 errored = true;
146 if (timeoutConfig.dieOnTimeout) {
147 reject(Error(errMsg));
148 } else {
149 console.error(errMsg);
150 //don't resolve or reject, we're waiting this one out
151 }
152 } else if (!errored) {
153 const numWarnings = shouldError;
154 const numMillis = numWarnings * warningPeriod;
155 console.warn(errMsg);
156 if (numMillis + warningPeriod < timeoutConfig.millis) {
157 setTimeout(() => maybeTimingOut(numWarnings + 1), warningPeriod);
158 }
159 }
160 }
161 }
162 });
163}
164
165export function ensureValidAppTimeouts(timeouts) {

Callers 5

toUnloadPromiseFunction · 0.90
toBootstrapPromiseFunction · 0.90
toMountPromiseFunction · 0.90
unmountAppOrParcelFunction · 0.90
toUpdatePromiseFunction · 0.90

Calls 5

objectTypeFunction · 0.90
getPropsFunction · 0.90
formatErrorMessageFunction · 0.90
toNameFunction · 0.90
maybeTimingOutFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…