How to use the socketcluster/scworker.create function in socketcluster

To help you get started, we’ve selected a few socketcluster examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LiskHQ / lisk-sdk-examples / framework / src / modules / chain / workers_controller.js View on Github external
const PeersUpdateRules = require('./api/ws/workers/peers_update_rules');
const Rules = require('./api/ws/workers/rules');
const failureCodes = require('./api/ws/rpc/failure_codes');
const { createLoggerComponent } = require('../../../src/components/logger');

const validator = require('../../controller/validator');
const schema = require('./defaults/config');

const config = validator.parseEnvArgAndValidate(schema, {});

/**
 * Instantiate the SocketCluster SCWorker instance with custom logic
 * inside the run function. The run function is invoked when the worker process
 * is ready to accept requests/connections.
 */
SCWorker.create({
	// Pass the custom configuration to P2P HTTP Server to mitigate the security vulnerabilities fixed by Node v8.14.0 - "Slowloris (cve-2018-12122)"
	createHTTPServer() {
		const httpServer = http.createServer();
		httpServer.headersTimeout = config.network.options.httpHeadersTimeout;
		httpServer.setTimeout(config.network.options.httpServerSetTimeout);
		httpServer.on('timeout', socket => {
			socket.destroy();
		});
		return httpServer;
	},
	run() {
		const self = this;
		const scServer = this.getSCServer();

		async.auto(
			{

socketcluster

Highly scalable realtime framework with support for async/await

MIT
Latest version published 1 month ago

Package Health Score

65 / 100
Full package analysis