MCPcopy Create free account
hub / github.com/reactnativecn/react-native-update / waitForServer

Function waitForServer

Example/e2etest/e2e/globalSetup.ts:125–157  ·  view source on GitHub ↗
(timeoutMs = 30000)

Source from the content-addressed store, hash-verified

123}
124
125function waitForServer(timeoutMs = 30000) {
126 const start = Date.now();
127 const url = `http://127.0.0.1:${LOCAL_UPDATE_PORT}/health`;
128
129 return new Promise<void>((resolve, reject) => {
130 const poll = () => {
131 const req = http.get(url, res => {
132 if (res.statusCode === 200) {
133 resolve();
134 return;
135 }
136 retry();
137 });
138 req.on('error', retry);
139 req.setTimeout(1000, () => {
140 req.destroy();
141 retry();
142 });
143 };
144
145 const retry = () => {
146 if (Date.now() - start > timeoutMs) {
147 reject(
148 new Error('Local artifacts server did not become ready in time.'),
149 );
150 return;
151 }
152 setTimeout(poll, 300);
153 };
154
155 poll();
156 });
157}
158
159function sleep(ms: number) {
160 return new Promise(resolve => setTimeout(resolve, ms));

Callers 1

globalSetupFunction · 0.70

Calls 1

pollFunction · 0.70

Tested by

no test coverage detected