44 lines
1.0 KiB
JavaScript
44 lines
1.0 KiB
JavaScript
|
import Base from '../src/base'
|
||
|
|
||
|
// const USOCKET = __dirname + '/sample.sock'
|
||
|
|
||
|
let dy = new Base({id:'dynamic'})
|
||
|
|
||
|
;
|
||
|
(async () => {
|
||
|
|
||
|
|
||
|
await dy.init()
|
||
|
console.log('started', dy.started)
|
||
|
await Promise.all([dy.addSocket('con','c','t'),dy.addSocket('ser','s','t')])
|
||
|
|
||
|
dy.good = {
|
||
|
bad: function(packet){
|
||
|
return new Promise( async (resolve) => {
|
||
|
let res = {}
|
||
|
res.req = packet
|
||
|
res.cmd='good/ugly'
|
||
|
res.response='The Good The Bad and The Ugly'
|
||
|
return resolve(res)
|
||
|
})
|
||
|
},
|
||
|
ugly: function (packet) {
|
||
|
console.log('==============reply from Good Bad command =========')
|
||
|
console.log(packet.response)
|
||
|
console.log('===========================')
|
||
|
}
|
||
|
}
|
||
|
|
||
|
let packet = {}
|
||
|
// console.log('=============sending============')
|
||
|
packet = {cmd:'good:bad'}
|
||
|
console.log(packet)
|
||
|
await dy.send(packet)
|
||
|
|
||
|
process.kill(process.pid, 'SIGTERM')
|
||
|
|
||
|
})().catch(err => {
|
||
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
||
|
process.kill(process.pid, 'SIGTERM')
|
||
|
})
|