1.0.33 • Published 6 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
6 years ago
1.0.32
6 years ago
1.0.31
6 years ago
1.0.30
6 years ago
1.0.29
6 years ago
1.0.28
6 years ago
1.0.27
6 years ago
1.0.26
6 years ago
1.0.25
6 years ago
1.0.24
6 years ago
1.0.22
6 years ago
1.0.23
6 years ago
1.0.21
6 years ago
1.0.20
6 years ago
1.0.19
6 years ago
1.0.18
6 years ago
1.0.17
6 years ago
1.0.16
6 years ago
1.0.15
6 years ago
1.0.14
6 years ago
1.0.13
6 years ago
1.0.12
6 years ago
1.0.11
6 years ago
1.0.10
6 years ago
1.0.9
6 years ago
1.0.8
6 years ago
1.0.7
6 years ago
1.0.6
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago