MCPcopy
hub / github.com/redfin/react-server / serverToStopPromise

Function serverToStopPromise

packages/react-server-cli/src/commands/start.js:23–56  ·  view source on GitHub ↗
(server)

Source from the content-addressed store, hash-verified

21// returns a method that can be used to stop the server. the returned method
22// returns a promise to indicate when the server is actually stopped.
23const serverToStopPromise = (server) => {
24
25 const sockets = [];
26
27 // If we're testing then we want to be able to bail out quickly. Zombie
28 // (the test browser) makes keepalive connections to our static asset
29 // server, and we don't need to be polite to it when we're tearing down.
30 if (process.env.NODE_ENV === "test") { // eslint-disable-line no-process-env
31 server.on('connection', socket => sockets.push(socket));
32 }
33
34 return () => {
35 return new Promise((resolve, reject) => {
36
37 // This will only have anything if we're testing. See above.
38 sockets.forEach(socket => socket.destroy());
39
40 server.on('error', (e) => {
41 logger.error('An error was emitted while shutting down the server');
42 logger.error(e);
43 reject(e);
44 });
45 server.close((e) => {
46 if (e) {
47 logger.error('The server was not started, so it cannot be stopped.');
48 logger.error(e);
49 reject(e);
50 return;
51 }
52 resolve();
53 });
54 });
55 };
56};
57
58
59

Callers 3

startHtmlServerFunction · 0.85
startStaticJsServerFunction · 0.85
startHotLoadJsServerFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…