3.0.6 • Published 5 years ago
the-seat v3.0.6
the-seat
Shared value manager
Installation
$ npm install the-seat --save
Usage
'use strict'
const theSeat = require('the-seat')
async function tryExample () {
const seat = theSeat()
{
const ports = seat.scope('ports')
{
const myapp01 = ports.bind('myapp01')
console.log(myapp01.canTake(3000)) // -> true
myapp01.take(3000)
console.log(myapp01.canTake(3000)) // -> true
console.log(myapp01.get()) // -> false
}
{
const myapp02 = ports.bind('myapp02')
console.log(myapp02.canTake(3000)) // -> false, because myapp01 already took it.
myapp02.take(3001)
/* ... */
}
{
// Define utility method to take port
const portFor = (name, portBase = 3000) => {
const {get, take, has, canTake} = ports.bind(name)
if (has()) {
return get()
}
let taking = portBase
while (!canTake(taking)) {
taking += 1
}
take(taking)
return get()
}
const portForApp3 = portFor('myapp03')
/* ... */
}
}
}
tryExample().catch((err) => console.error(err))
API Guide
License
This software is released under the MIT License.
Links
3.0.6
5 years ago
3.0.4
5 years ago
3.0.3
5 years ago
3.0.1
6 years ago
2.0.3
6 years ago
2.0.2
6 years ago
2.0.1
6 years ago
2.0.0
6 years ago
1.7.1
6 years ago
1.7.0
6 years ago
1.6.1
6 years ago
1.6.0
6 years ago
1.4.1
7 years ago
1.4.0
7 years ago
1.2.1
7 years ago
1.2.0
7 years ago
1.1.0
7 years ago
1.0.2
7 years ago
1.0.1
7 years ago
1.0.0
7 years ago