geis
v0.1.0
Published
RethinkDB backed distributed lock
Downloads
6
Readme
Geis
npm install geis
A RethinkDB backed distributed lock.
import Geis from "geis"
Geis.create("user:emails").then( lock => {
// tell the world!
this.emit("lock", lock)
})
// somewhere else
lock.synchronize( done => {
Users.count({ email : req.body.email }).then( n => {
if (n > 0) {
res.status(400).json({ error: "this email is already registered for an account" })
return done()
}
// transparently handles promises to allow for flatter code structures
return User.create({ email : req.body.email }).then( user => {
res.json({ message : "successfully registered!" })
}).catch( err => {
res.status(500).message({ error: err.message })
})
})
})