1.0.0 • Published 3 years ago
lock-em-sock-em v1.0.0
lock'em sock'em
atomic, cross-platform tcp domain servers & sockets
Install
npm i lock-em-sock-em
Usage
const { createServer, connect, lockemSockem } = require('lock-em-sock-em')
const id = 'lock-em-sock-em'
const server = await createServer(id)
server.on('connection', async (socket) => {
let str = ''
for await (const buf of socket) str += buf
console.log(str)
})
const socket = await connect(id)
socket.write(Buffer.from(id))
socket.end()
const { acquired } = await lockemSockem(id)
console.log('acquired file lock?', acquired)API
const server = await createServer(id)
server is an instance of net.Server()
const socket = await connect(id)
socket is an instance of net.Socket()
const { handle, lock, acquired, sock } = await lockemSockem(id)
handleis an instance offs.FileHandlelockis theStringpath of the file lockacquiredis aBooleanindicating whether the file lock was successfully acquiredsockis theStringpath of the domain socket
1.0.0
3 years ago