/* simple generic consumer sending an ack * */ import Base from '../src/base' const delay = time => new Promise(res=>setTimeout(()=>res(),time)) let opts={name:'example-consumer', id:'example-consumer'} let consumer = new Base(opts) ; (async () => { // consumer.on('log',ev => { switch (ev.level) { // case 'warning': // case 'error': case 'testing': // case 'fatal': console.log(ev.level.toUpperCase(),'\n',ev) break } }) // example return processor using a namespace, will take precidence over default and root namespaces consumer.cmds = { reply: (packet) => { // console.log('------REPLY--via cmds namespace----') // console.log(packet) }, error: (packet) => { console.log('------Error--via cmds namespace----') console.log(packet) } } consumer.addNamespace('cmds','c') // comment this out to process via root namespace consumer.registerSocket('to-example-socket','c','n',{name:'example-consumer', path:'named-pipe'}) consumer.ready.addObserver('example-socket:process') consumer.on('example-socket:process', (ready,packet) => { console.log('process state from socket', ready) }) let res = await consumer.init() if (res.error) { console.log('errors during init') process.kill(process.pid, 'SIGTERM') } consumer.ready.subscribe(async ready=>{ console.log('consumer can be ready when socket process pushes it is ready', ready) }) process.once('SIGINT', function() { console.log('Caught interrupt signal') consumer.removeAllListeners() process.exit() }) process.once('SIGUSR2', async () => { consumer.removeAllListeners() process.exit() }) })().catch(err => { console.error('FATAL: UNABLE TO START SYSTEM!\n',err) consumer.removeAllListeners() process.kill(process.pid, 'SIGTERM') })