connectors refactor

This commit is contained in:
Jan Prochazka
2020-01-04 21:59:53 +01:00
parent 235ef4764b
commit 948af4984b
12 changed files with 130 additions and 46 deletions

View File

@@ -0,0 +1,11 @@
process.on('message', async connection => {
try {
const driver = require(`../engines/${connection.engine}/index`);
const conn = await driver.connect(connection);
const res = await driver.getVersion(conn);
process.send(res);
} catch (e) {
console.log(e);
process.send({ error: e.message });
}
});

View File

@@ -0,0 +1,20 @@
function handleConnect() {}
const messageHandlers = {
connect: handleConnect,
};
function handleMessage({ type, ...other }) {
const handler = messageHandlers[type];
handler(other);
}
process.on('message', async connection => {
try {
const connectFunc = require(`../engines/${connection.engine}/connect`);
const res = await connectFunc(connection);
process.send(res);
} catch (e) {
process.send({ error: e.message });
}
});