setup each service characteristic of the sensor to emit data on new data
when all have been setup with characteristic.notify then resolve the promise
@param {error}
496921
function setupEmitter(error) {
      if (error) { return reject(error); }

      const sensorService = getService(SERVICE_SENSOR_UUID, peripheral);
      const notifiable = sensorService.characteristics;
      const withNotified = Promise.all(notifiable.map(characteristic =>
        new Promise((resolve, reject) =>
          void characteristic.notify([], error =>
            void (!!error ? reject(error) : resolve(characteristic))))));

      withNotified.then(characteristics => {
        const emitter = new EventEmitter();
        const onData = uuid => buffer =>
          void emitter.emit("data", { characteristic: uuid, buffer });

        characteristics.forEach(characteristic =>
          void characteristic.on('data', onData(characteristic.uuid)));

        const matrixCharacteristic =
          getCharacteristic(CHARACTERISTIC_MATRIX_UUID,
            getService(SERVICE_MATRIX_UUID, peripheral));

        resolve(new client.NuimoClient(emitter, matrixCharacteristic, peripheral));
      }).catch(reject);
    }
730024
def start_notify!(service, characteristic)
      char= _find_characteristic(service, characteristic)
      if char.flag?('notify')
        char.notify!
      else
        raise OperationNotSupportedError.new("No notifications available for characteristic #{characteristic}")
      end
    end
330887
function add() {
            vm.error = undefined;
            service.add({
                description: vm.description
            }, function() {
                _fetch();
            }, function() {
                vm.error = 'An error occurred when adding a todo';
            });
            vm.description = '';
        }
638193
function(properties) {
        this._handle = null;
        this._services = null;
        this._characteristics = null;

        this.device = null;
        this.uuid = null;
        this.isPrimary = false;

        mergeDictionary(this, properties);
        this.dispatchEvent({ type: "serviceadded", bubbles: true });
    }
883488
function promesify(err, res) {
    if (!err) return Promise.resolve(res);
    else return Promise.reject(err);
}
768258
function setErrorInfo(promise, errorId, isException) {
        promise._isException = isException || false;
        promise._errorId = errorId;
    }
308941
function()
    {
        var _this = this;

        _(api.services).each(function(service, key) {
            _this._addService(service);
        });
    }
475224
function observePromise(proxy, promise) {
  promise.then(value => {
    set(proxy, 'isFulfilled', true);
    value._settingFromFirebase = true;
    set(proxy, 'content', value);
    value._settingFromFirebase = false;
  }, reason => {
    set(proxy, 'isRejected', true);
    set(proxy, 'reason', reason);
    // don't re-throw, as we are merely observing
  });
}
259751
function(args, connectionInfo) {
  // args.consignmentIdToProductIdMap.value MUST already be set by the caller
  // args.consignmentProductId.value MUST be set for the very first call
  args.arrayIndex = {value: 0};
  args.consignmentProductId = {value: args.consignmentIdToProductIdMap.value[args.arrayIndex.value].productId};
  args.getArray = function(){
    return this.consignmentIdToProductIdMap.value;
  };
  args.getArrayIndex = function(){
    return this.arrayIndex.value;
  };

  // iterate serially through a promise chain for all args.consignmentIds.value
  return utils.processPromisesSerially(
    args.getArray(),
    args.getArrayIndex(),
    args,
    function mergeStrategy(newData, previousData, args){
      log.debug('resolveMissingSuppliers - inside mergeStrategy()');
      var product = newData.products[0];
      //log.silly('newData: ', newData);
      //log.silly('product: ', product);
      var updateMe = args.getArray()[args.getArrayIndex()];
      updateMe.supplier = product.supplier_name || product.supplier_code;
      log.debug('updated consignmentIdToProductIdMap: ', args.getArray()[args.getArrayIndex()]);

      previousData = args.getArray();
      return Promise.resolve(previousData); // why do we need a promise?
    },
    function setupNext(updateArgs){
      log.debug('resolveMissingSuppliers - inside setupNext()');
      updateArgs.arrayIndex.value = updateArgs.getArrayIndex() + 1;
      if (updateArgs.getArrayIndex() < updateArgs.getArray().length) {
        updateArgs.consignmentProductId.value = updateArgs.getArray()[updateArgs.getArrayIndex()].productId;
        log.debug('resolveMissingSuppliers - next is consignmentId: ' + updateArgs.consignmentProductId.value);
      }
      else {
        updateArgs.consignmentProductId.value = null;
        log.debug('resolveMissingSuppliers - finished iterating through all the consignmentIds');
      }
      return updateArgs;
    },
    function executeNext(updatedArgs){
      log.debug('resolveMissingSuppliers - inside executeNext()');
      log.debug('resolveMissingSuppliers - executing for consignmentProductId: ' + updatedArgs.consignmentProductId.value);
      //log.silly('updatedArgs: ', updatedArgs);
      var args = argsForInput.products.fetchById();
      args.apiId.value = updatedArgs.consignmentProductId.value;
      return product.endpoints.fetchProduct(args, connectionInfo);
    }
  );
}
785099
function (providerConstr, args) {
    return new Promise(function (resolve) {
        var instance = new providerConstr();
        addInstanceToStore(args, instance);
        createGetData(instance, args.caller);
        if (args.hasOwnProperty("handler")) {
            instance.setHandler(args.handler);
        }
        if (args.hasOwnProperty("resources")) {
            instance.setResources(args.resources);
        }
        instance.fetchData(resolve, args.caller);
    });
}
892377
function(data, errorMessages){
	this.reset();

	if(data) this.setData(data);

	if(errorMessages)
		this.setErrorMessages(errorMessages);
	else
		this.setErrorMessages(require('./errorMessages'));
}
225477
function onIceCandidate(id,data)
    {
        if(scope.hasWebRTCSupport())
        {
            getOrCreatePeer(id).onServerMessage(JSON.parse(data));
        }
    }
1041600
function(stateOnDefined) {
      const onDefinitionError = (err) => {
        this.failedWith = err;
        this.transition('failed');
      };
      const onDefined = () => {
        this.transition(stateOnDefined);
      };
      this.channel.define()
        .then(onDefined, onDefinitionError);
    }
1072547
function notify(listener) {
    var func = state == webdriver.promise.Deferred.State_.RESOLVED ?
        listener.callback : listener.errback;
    if (func) {
      flow.runInNewFrame_(goog.partial(func, value),
          listener.fulfill, listener.reject);
    } else if (state == webdriver.promise.Deferred.State_.REJECTED) {
      listener.reject(value);
    } else {
      listener.fulfill(value);
    }
  }
591391
function triggerPromise() {
        var me = this;
        var args = arguments;

        var canHandlePromise =
            this.children.indexOf("completed") >= 0 &&
            this.children.indexOf("failed") >= 0;

        var createdPromise = new PromiseFactory(function(resolve, reject) {
            // If `listenAndPromise` is listening
            // patch `promise` w/ context-loaded resolve/reject
            if (me.willCallPromise) {
                _.nextTick(function() {
                    var previousPromise = me.promise;
                    me.promise = function (inputPromise) {
                        inputPromise.then(resolve, reject);
                        // Back to your regularly schedule programming.
                        me.promise = previousPromise;
                        return me.promise.apply(me, arguments);
                    };
                    me.trigger.apply(me, args);
                });
                return;
            }

            if (canHandlePromise) {
                var removeSuccess = me.completed.listen(function () {
                    var args = Array.prototype.slice.call(arguments);
                    removeSuccess();
                    removeFailed();
                    resolve(args.length > 1 ? args : args[0]);
                });

                var removeFailed = me.failed.listen(function () {
                    var args = Array.prototype.slice.call(arguments);
                    removeSuccess();
                    removeFailed();
                    reject(args.length > 1 ? args : args[0]);
                });
            }

            _.nextTick(function () {
                me.trigger.apply(me, args);
            });

            if (!canHandlePromise) {
                resolve();
            }
        });

        // Ensure that the promise does trigger "Uncaught (in promise)" errors in console if no error handler is added
        // See: https://github.com/reflux/reflux-promise/issues/4
        createdPromise.catch(function() {});

        return createdPromise;
    }
404156
async function setup (payload, ...args) {
    let msg = await store.logon(payload);
    prtUtil.print(`Logon status: ${msg}`);
    debugger;
    let {compute, casManagement} = await store.addServices(...args);
    let istore = store.store;

    let newStore = restaf.restoreStore(istore);
    console.log(newStore);
    console.log(newStore.getServices());
    let {files} = await newStore.addServices('files');
    console.log(newStore.getServices());
    return true;
    }
446488
function doit(originalArgs, originalSettings, jqOptions, bjOptions) {
    var xhr;
    var p = new Promise(function resolver(resolve, reject) {
      xhr = bluetry.perform.call(this, originalSettings, jqOptions, bjOptions);
      function succeded(data, textStatus, jqXHR) {
        resolve(bjOptions.verboseResults ? [data, textStatus, jqXHR] : data);
      }

      function failed(jqXHR, textStatus, errorThrown) {
        var error = makeError(
          jqXHR, textStatus, errorThrown,
          bjOptions.verboseExceptions ? originalArgs : null);

        if (!isNetworkIssue(error)) {
          // As mentioned earlier, errors that are not due to the network cause
          // an immediate rejection: no diagnosis.
          reject(error);
        }
        else {
          // Move to perhaps diagnosing what could be the problem.
          var diagnose = bjOptions.diagnose;
          if (!diagnose || !diagnose.on) {
            // The user did not request diagnosis: fail now.
            reject(error);
          }
          else {
            // Otherwise, we perform the requested diagnosis.  We cannot just
            // call ``reject`` with the return value of ``diagnoseIt``, as the
            // rejection value would be a promise and not an error. (``resolve``
            // assimilates promises, ``reject`` does not).
            resolve(diagnoseIt(error, diagnose));
          }
        }
      }

      xhr.fail(failed).done(succeded);
    });

    return { xhr: xhr, promise: p };
  }