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

Function waitForServer

Example/testHotUpdate/e2e/globalSetup.js:63–93  ·  view source on GitHub ↗
(timeoutMs = 30000)

Source from the content-addressed store, hash-verified

61}
62
63function waitForServer(timeoutMs = 30000) {
64 const start = Date.now();
65 const url = `http://127.0.0.1:${LOCAL_UPDATE_PORT}/health`;
66
67 return new Promise((resolve, reject) => {
68 const poll = () => {
69 const req = http.get(url, res => {
70 if (res.statusCode === 200) {
71 resolve(void 0);
72 return;
73 }
74 retry();
75 });
76 req.on('error', retry);
77 req.setTimeout(1000, () => {
78 req.destroy();
79 retry();
80 });
81 };
82
83 const retry = () => {
84 if (Date.now() - start > timeoutMs) {
85 reject(new Error('Local artifacts server did not become ready in time.'));
86 return;
87 }
88 setTimeout(poll, 300);
89 };
90
91 poll();
92 });
93}
94
95module.exports = async () => {
96 const platform = process.env.E2E_PLATFORM || 'ios';

Callers 1

globalSetup.jsFile · 0.70

Calls 1

pollFunction · 0.70

Tested by

no test coverage detected