lock-em-sock-em
v1.0.0
Published
atomic, cross-platform tcp domain servers & sockets
Downloads
1
Readme
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)
handle
is an instance offs.FileHandle
lock
is theString
path of the file lockacquired
is aBoolean
indicating whether the file lock was successfully acquiredsock
is theString
path of the domain socket