ipc-pager

1.0.33 • Public • Published

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)

Readme

Keywords

none

Package Sidebar

Install

npm i ipc-pager

Weekly Downloads

0

Version

1.0.33

License

ISC

Unpacked Size

13.4 kB

Total Files

6

Last publish

Collaborators

  • r3volved