1.0.33 • Published 4 years ago
ipc-pager v1.0.33
ipc-pager
Simple fs-socketed ipc handler with Server, Client and Messenger
Usage
Install with npm
npm i ipc-pager
Simple server example
//Define your socket handle
const HANDLE = '/tmp/pagetest.sock'
//Define your communication routing
const ROUTES = {
short : async ( data ) => {
console.log('-short test-',data)
return 'short result'
},
long : async ( data ) => {
console.log('-long test-',data)
await new Promise(end => setTimeout(end,5000))
return 'long result'
},
longer : async ( data ) => {
console.log('-long test-',data)
await new Promise(end => setTimeout(end,10000))
return 'long result'
}
}
//Initialize a Server with handle and routing
const Pager = require('ipc-pager')
const server = Pager(HANDLE).Server(ROUTES)
server.start()
.then(() => console.log(`Pager listening to ${HANDLE}`))
Simple messenger example
//Define your socket handle
const HANDLE = '/tmp/pagetest.sock'
//Initialize a messenger to handle
const Pager = require('ipc-pager')
const messenger = Pager(HANDLE).Messenger
//Send a message and log the resulting buffer
messenger({ action:'short', data:'Some test data' })
.then(buf => console.log(buf.toString()))
.catch(console.error)
Alternative return types
buffer (default)
//Send a message and log the resulting json
messenger({ action:'long', data:'Some test data' })
.then(console.log)
.catch(console.error)
json
//Send a message and log the resulting json
messenger({ action:'long', data:'Some test data' }, 'json')
.then(console.log)
.catch(console.error)
string
//Send a message and log the resulting string
messenger({ action:'longer', data:'Some test data' }, 'string')
.then(console.log)
.catch(console.error)
1.0.33
4 years ago
1.0.32
4 years ago
1.0.31
4 years ago
1.0.30
4 years ago
1.0.29
4 years ago
1.0.28
4 years ago
1.0.27
4 years ago
1.0.26
4 years ago
1.0.25
4 years ago
1.0.24
4 years ago
1.0.22
4 years ago
1.0.23
4 years ago
1.0.21
4 years ago
1.0.20
4 years ago
1.0.19
4 years ago
1.0.18
4 years ago
1.0.17
4 years ago
1.0.16
4 years ago
1.0.15
4 years ago
1.0.14
4 years ago
1.0.13
4 years ago
1.0.12
4 years ago
1.0.11
4 years ago
1.0.10
4 years ago
1.0.9
4 years ago
1.0.8
4 years ago
1.0.7
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.2
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago