Narcissistic, Perfectly Modest

    reservable

    0.1.3 • Public • Published

    reservable

    npm versiontravis buildjavascript standard style


    socketeer server middleware and client to simplify client action reservations. think: mutex

    documentation


    server example

    var socketeer = require('socketeer')
    var reservable = require('reservable')
     
    var io = new socketeer.Server()
     
    var reserve = new reservable.Server(io, {
      actions: ['item-feed']
    })
     
    var feedAction = reserve.action('item-feed')
     
    feedAction.onBeforeReserve = function (callback) {
      if (busyProcessingFeed) {
        return callback(null, 'BUSY')
      }
      return callback()
    }
     
    feedAction.onData = function (data, callback) {
      var sku = processItem(data)
      callback(null, sku)
    }
     
    feedAction.onRelease = function (cleanRelease) {
      startProcessingFeed()
    }
     
    io.listen(12345)
     

    client example

    var socketeer = require('socketeer')
    var reservable = require('reservable')
     
    var io = new socketeer.Client('ws://example.com')
     
    var feed = new reservable.Client(io, 'item-feed')
     
    io.on('open', function () {
      feed.reserve().then(function () {
        return feed.send('some stuff')
      }).then(function () {
        return feed.release()
      }).catch(function (err) {
        console.log('got error: ' + err)
      })
    })
     

    Install

    npm i reservable

    DownloadsWeekly Downloads

    21

    Version

    0.1.3

    License

    MIT

    Last publish

    Collaborators

    • str_t