code: function lock(key) {
      var promise = new Promise(function(resolve, reject) {
  
          wait(key, function(key) {
              var released = false;
              var lock = function() {
                  if (!released) {
                      free(key);
                      released = true;
                  }
              };
              lock.key = key;
  
              resolve(lock);
          });
      });
  
      tick(key);
  
      return promise;
  }
docs: Returns a promise for a resource lock that resolves into
  a function to release that lock again.
  
  Usage:
  var l1 = lock("foo");
  l1.then(function(l) {
  // do your work
  // l.key contains the key of the locked_item
  l(); /release the lock
  });
  
  @param {string} identifier for a resource to be locked
  @returns {Promise} A Promise that resolves when the lock is obtained