mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-30 14:02:44 +08:00
[react-packager] Expose a socket interface
Summary: Buck (our build system) currently starts multiple packager instances for each target and may build multiple targets in parallel. This means we're paying startup costs and are duplicating the work. This enables us to start one instance of the packager and connect to it via socket to do all the work that needs to be done. The way this is structured: 1. SocketServer: A server that listens on a socket path that is generated based on the server options 2. SocketClient: Interfaces with the server and exposes the operations that we support as methods 3. SocketInterface: Integration point and responsible for forking off the server
This commit is contained in:
35
packager/react-packager/__mocks__/net.js
vendored
35
packager/react-packager/__mocks__/net.js
vendored
@@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var servers = {};
|
||||
exports.createServer = function(listener) {
|
||||
var server = {
|
||||
_listener: listener,
|
||||
|
||||
socket: new EventEmitter(),
|
||||
|
||||
listen: function(path) {
|
||||
listener(this.socket);
|
||||
servers[path] = this;
|
||||
}
|
||||
};
|
||||
|
||||
server.socket.setEncoding = function() {};
|
||||
server.socket.write = function(data) {
|
||||
this.emit('data', data);
|
||||
};
|
||||
|
||||
return server;
|
||||
};
|
||||
|
||||
exports.connect = function(options) {
|
||||
var server = servers[options.path || options.port];
|
||||
return server.socket;
|
||||
};
|
||||
Reference in New Issue
Block a user