uci-interrupt/examples/client.js

38 lines
961 B
JavaScript

import Base from '@uci/base'
// const HOST = 'localhost'
const HOST = 'sbc'
const PORT = 9024
let processor = new Base({sockets:'inter#c>t', inter:{host:HOST, port:PORT}, id:'interrupt-processor', useRootNS:true})
processor.interrupt = async function (packet) {
return new Promise((resolve) => {
console.log('interrupt occured')
console.dir(packet)
resolve({status: 'processed'})
})
}
processor.reply = async function (packet) {
return new Promise((resolve) => {
console.log('reply from interrupt with packet')
console.dir(packet)
resolve({status: 'processed'})
})
}
;
(async () => {
await processor.init()
console.log('====sending fire command to interrupt===')
await processor.send({cmd: 'fire'})
console.log('====sending fire command to interrupt===')
await processor.send({cmd: 'fire'})
// process.kill(process.pid, 'SIGTERM')
})().catch(err => {
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
})