converts a node.js async op into a promise w/boxed resolved value(s)
171244
function promisify(op) {
    var args = slice.call(arguments, 1);
    return new Promise(function(resolver) {
      op.apply(null, args.concat(function(err, value) {
        if(err) {
          resolver.reject(err);
        }
        else {
          resolver.resolve(value);
        }
      }));
    });
  }
281275
function(input, callback, context, remoteData)
  {
    var db = this;
    var promise = new Promise();

    promise.success( callback, context || db );

    function checkModel()
    {
      var result = db.parseModel( input, remoteData );

      if ( result !== false && !promise.isComplete() && db.initialized )
      {
        var remoteLoaded = db.remoteLoaded || !db.hasLoad( Load.All );
        var missingModel = (result === null || !result.$isSaved());
        var lazyLoad = db.hasLoad( Load.Lazy );

        if ( lazyLoad && remoteLoaded && missingModel )
        {
          if ( !result )
          {
            result = db.keyHandler.buildObjectFromKey( db.keyHandler.buildKeyFromInput( input ) );
          }

          result.$once( Model.Events.RemoteGets, function()
          {
            if ( !promise.isComplete() )
            {
              if ( isObject( input ) )
              {
                result.$set( input );
              }

              promise.resolve( result.$isSaved() ? result : null );
            }
          });

          result.$refresh( Cascade.All, db.fetchOptions );
        }
        else
        {
          promise.resolve( result );
        }
      }

      return promise.isComplete() ? false : true;
    }

    if ( checkModel() )
    {
      db.ready( checkModel, db, true );
    }

    return promise;
  }
855426
function asPromise (val) {
	if (val && typeof val.then === 'function') {
		return val;
	}
	var deferred = new PromiseFactory();
	deferred.resolve(val);
	return deferred.promise();
}
932420
function ( x ) {

		if ( Util.is.Error( x ) ) {
			return this.reject( x );
		}

		// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
		try {

			if ( x === this ) {
				throw new TypeError('A promise cannot be resolved with itself.');
			}

			if ( Util.is.Promise( x ) || ( x !== null && Util.is.Object( x ) && Util.is.Function( x.then ) ) ) {
				Promise.doResolve( x.then.bind( x ), this.resolve, this.reject );
				return this;
			}

			if ( Util.is.Function( x ) ) {
				Promise.doResolve( x, this.resolve, this.reject );
				return this;
			}

			this.fulfill( x );

		} catch ( error ) {

			return this.reject( error );

		}

		return this;
	}
497684
function singleStringCoding(stream, string, on_finish, on_progress) {
  on_progress = on_progress || function() {};
  on_finish = on_finish || function() {};

  // possibly our input is an array of byte integers
  // or a typed array
  if (!Buffer.isBuffer(string))
    string = Buffer.from(string);

  var deferred = {}, failed = false;

  stream.once('error', function(err) {
    failed = true;
    on_finish(null, err);
  });

  // emulate Promise.defer()
  deferred.promise = new Promise(function(resolve, reject) {
    deferred.resolve = resolve;
    deferred.reject = reject;
  });

  // Since using the Promise API is optional, generating unhandled
  // rejections is not okay.
  deferred.promise.catch(noop);

  stream.once('error', function(e) {
    deferred.reject(e);
  });

  var buffers = [];

  stream.on('data', function(b) {
    buffers.push(b);
  });

  stream.once('end', function() {
    var result = Buffer.concat(buffers);

    if (!failed) {
      on_progress(1.0);
      on_finish(result);
    }

    if (deferred)
      deferred.resolve(result);
  });

  on_progress(0.0);

  stream.end(string);

  if (deferred)
    return deferred.promise;
}
31463
function parsePromiseLib(pl) {

    let promise;
    if (pl instanceof PromiseAdapter) {
        promise = function (func) {
            return pl.create(func);
        };
        promise.resolve = pl.resolve;
        promise.reject = pl.reject;
        promise.all = pl.all;
        return promise;
    }
    const t = typeof pl;
    if (t === 'function' || t === 'object') {
        const Root = typeof pl.Promise === 'function' ? pl.Promise : pl;
        promise = function (func) {
            return new Root(func);
        };
        promise.resolve = Root.resolve;
        promise.reject = Root.reject;
        promise.all = Root.all;
        if (typeof promise.resolve === 'function' &&
            typeof promise.reject === 'function' &&
            typeof promise.all === 'function') {
            return promise;
        }
    }

    throw new TypeError('Invalid promise library specified.');
}
698009
async function () {
    const encodedABI = simpleTokenContractObj.methods.transfer(receiverAddress, bigNumAmount.toString(10)).encodeABI();

    const estimateGasObj = new EstimateGasKlass({
      contract_name: simpleTokenContractName,
      contract_address: oThis.contractAddress,
      chain: 'value',
      sender_address: senderAddress,
      method_name: 'transfer',
      method_arguments: [receiverAddress, bigNumAmount.toString(10)]
    });

    const estimateGasResponse = await estimateGasObj.perform()
      , gasToUse = estimateGasResponse.data.gas_to_use
    ;

    // set txParams for firing event
    const rawTxParams = {
      from: senderAddress, to: receiverAddress, value: bigNumAmount.toString(10),
      gasPrice: VC_GAS_PRICE, gas: gasToUse
    };

    // set params in notification data
    notificationData.message.payload.params.txParams = rawTxParams; // one time

    // set txParams for executing transaction
    const txParams = {
      from: senderAddress,
      to: oThis.contractAddress,
      data: encodedABI,
      gasPrice: VC_GAS_PRICE,
      gas: gasToUse
    };

    // Unlock account and send transaction
    return new Promise(function (onResolve, onReject) {
      const onReceipt = function (receipt) {
        // Publish event
        notificationData.message.kind = 'transaction_mined';
        openSTNotification.publishEvent.perform(notificationData);

        // send response
        if (basicHelper.isReturnTypeTxReceipt(returnType)) {
          return onResolve(responseHelper.successWithData({
            transaction_uuid: txUUID,
            transaction_hash: receipt.transactionHash,
            transaction_receipt: receipt
          }));
        }
      };

      web3Provider.eth.personal.unlockAccount(senderAddress, senderPassphrase)
        .then(function () {
          return web3Provider.eth.sendTransaction(txParams)
            .on('transactionHash', function (transactionHash) {
              // set transaction hash in notification data
              notificationData.message.payload.transaction_hash = transactionHash; // one time
              // Publish event
              notificationData.message.kind = 'transaction_initiated';
              openSTNotification.publishEvent.perform(notificationData);

              // send response
              if (basicHelper.isReturnTypeTxHash(returnType)) {
                return onResolve(responseHelper.successWithData({
                  transaction_uuid: txUUID,
                  transaction_hash: transactionHash,
                  transaction_receipt: {}
                }));
              }
            })
            .on('receipt', onReceipt)
        })
        .catch(async function (reason) {
          logger.error("ST :: Transaction failed.\n\t Reason:", reason);

          const onCatchError = function () {
            // set error data in notification data
            notificationData.message.payload.error_data = reason;
            // Publish event
            notificationData.message.kind = 'transaction_error';
            openSTNotification.publishEvent.perform(notificationData);

            // send response
            let errObj = responseHelper.error({
              internal_error_identifier: 'l_ci_st_transfer_6',
              api_error_identifier: 'transaction_failed',
              error_config: basicHelper.fetchErrorConfig()
            });
            return onResolve(errObj);
          };

          const isNotMinedInSomeBlocksError = reason.message.includes('not mined within');
          if (isNotMinedInSomeBlocksError) {
            // get receipt
            const res = await contractInteractHelper.getTransactionReceiptFromTrasactionHash(
              web3Provider,
              notificationData.message.payload.transaction_hash
            );

            if (res.isSuccess()) {
              onReceipt(res.data.receipt);
            } else {
              onCatchError();
            }
          } else {
            onCatchError();
          }

        });

    });

  }
299795
function valuePromise(value) {
  const p = new Promise(Promise._noop);
  p._state = 1;
  p._value = value;
  return p;
}
182413
async function repeatablePromise (initialAssumptions, assumptionsFromResult, promiseGenerator) {
    let promise = promiseGenerator(initialAssumptions);
    let result = await promise;
    let finalAssumptions = assumptionsFromResult(result);
    if (JSON.stringify(initialAssumptions) === JSON.stringify(finalAssumptions)) {
        return promise;
    } else {
        return promiseGenerator(finalAssumptions);
    }
}
1031224
function resolve(promiseLike) {

    // Return if already promised
    if (promiseLike instanceof Promise) {
        return promiseLike;
    }

    var promises = [];

    if (promiseLike instanceof Array) {
        promiseLike.forEach((promiseLikeEntry) => {
            promises.push(promisify(promiseLikeEntry));
        });
    }
    else if (promiseLike && (typeof promiseLike === "object")) {
        Object.keys(promiseLike).forEach((key) => {
            promises.push(promisify(promiseLike[key]));
        });
    }
    else {
        return promisify(promiseLike);
    }

    return Promise.all(promises).then((result) => {
        if (promiseLike instanceof Array) {
            return result;
        }

        var response = {};
        Object.keys(promiseLike).forEach((key, index) => {
            response[key] = result[index];
        });

        return response;
    });
}
883488
function promesify(err, res) {
    if (!err) return Promise.resolve(res);
    else return Promise.reject(err);
}
360534
function finishBasicPromise (resolve, reject) {
  return (err, res) => {
    if (err) {
      return reject(err);
    } else {
      return resolve(res);
    }
  };
}
853173
function saveAsync(doc) {
  return new Promise(function (resolve, reject) {
    doc.save(function (err, doc) {
      /* istanbul ignore if: This should handle errors just fine */
      if (err) { return reject(err); }
      resolve(doc);
    });
  });
}
1106438
function promisify(err, value, callback) {
  if (err) { throw err; }
  if (isPromiseLike(value)) {
    value.then(function(v) {
      callback(null, v);
    }, function(err) {
      callback(err);
    });
  } else {
    callback(null, value);
  }
}
556488
function handleAny (obj) {
    if (isPromiseAlike(obj)) {
      return obj.then(handleAny)
    } else if (isPlainObject(obj)) {
      return handleObject(obj)
    } else if (Object.prototype.toString.call(obj) === '[object Array]') {
      return handleArray(obj)
    } else {
      return new Promise(function (resolve, reject) {
        return resolve(obj)
      })
    }
  }
312741
function syncPromise(promise) {
  let isDone = false;
  let res, err;

  promise.then(
    value => {
      res = value;
      isDone = true;
    },
    error => {
      err = error;
      isDone = true;
    }
  );

  deasync.loopWhile(() => !isDone);

  if (err) {
    throw err;
  }

  return res;
}
596452
function createPromise(resolver) {
        return {
            'then': function (onFulfilled, onRejected) {
                return then(resolver, onFulfilled, onRejected);
            },

            'catch': function (onRejected) {
                return then(resolver, null, onRejected);
            }
        };
    }