/* putil-promisify
------------------------
(c) 2017-present Panates
SQB may be freely distributed under the MIT license.
For details and documentation:
https://panates.github.io/putil-promisify/
335953
function(fn) {
  if (promisify.isPromise(fn))
    return fn;
  if (typeof fn !== 'function')
    return promisify.Promise.resolve(fn);
  return new Promise((resolve, reject) => {
    try {
      const o = fn();
      if (promisify.isPromise(o)) {
        o.then(v => resolve(v))
            .catch((e) => reject(e));
      } else resolve(o);
    } catch (e) {
      reject(e);
    }
  });
}
382593
func (ma *markAllocator) put(mark uint32) {
	ma.lock.Lock()
	defer ma.lock.Unlock()
	ma.marks = append(ma.marks, mark)
}
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);
  }
}
1356997
func (c *RemoteClient) putMD5(sum []byte) error {
	if c.ddbTable == "" {
		return nil
	}

	if len(sum) != md5.Size {
		return errors.New("invalid payload md5")
	}

	putParams := &dynamodb.PutItemInput{
		Item: map[string]*dynamodb.AttributeValue{
			"LockID": {S: aws.String(c.lockPath() + stateIDSuffix)},
			"Digest": {S: aws.String(hex.EncodeToString(sum))},
		},
		TableName: aws.String(c.ddbTable),
	}
	_, err := c.dynClient.PutItem(putParams)
	if err != nil {
		log.Printf("[WARN] failed to record state serial in dynamodb: %s", err)
	}

	return nil
}
273759
function promisify_func(result_transformer) {
    result_transformer = result_transformer || identity;

    var transformer = function (func_promise) {
        return function (/* ... */) {
            var args = arguments;
            return result_transformer(when(func_promise, function (func) {
                return func.apply(null, args);
            }));
        };
    };

    transformer.for_property = function (obj_promise, prop) {
        return function (/* ... */) {
            var args = arguments;
            return result_transformer(when(obj_promise, function (obj) {
                return obj[prop].apply(obj, args);
            }));
        };
    };

    return transformer;
}
1028982
@Override
    public void squishToRange(double min, double max) {
        for (int i = 0; i < getFeatures().length(); i++) {
            double curr = (double) getFeatures().getScalar(i).element();
            if (curr < min)
                getFeatures().put(i, Nd4j.scalar(min));
            else if (curr > max)
                getFeatures().put(i, Nd4j.scalar(max));
        }
    }
668146
function promisify(f, args) {
  return new Promise((resolve, reject) => f.apply(this, args.concat((err, x) => err ? reject(err) : resolve(x))));
}
48353
function promisifyAll(sourceObject, keys){
    // promisified output
    const promisifiedFunctions = {};

    // process each object key
    for (const name of keys){
        // function exist in source object ?
        if (name in sourceObject && typeof sourceObject[name] === 'function'){
            // create promisified named version
            promisifiedFunctions[name] = _promisify(sourceObject[name], name);
        }
    }

    return promisifiedFunctions;
}
737274
func (containers Containers) stripProvisioningDuplicates() (deduplicated Containers) {
	seenProvisioningKeys := make(map[string]bool)
	for _, container := range containers {
		// for 2 containers that would the same provisioning
		// commands, the key should be equal
		key := container.BuildParams().Context() + "#" + container.Image()
		if _, ok := seenProvisioningKeys[key]; !ok {
			deduplicated = append(deduplicated, container)
			seenProvisioningKeys[key] = true
		}
	}
	return
}
502310
func Serialize(opts []*UnitOption) io.Reader {
	var buf bytes.Buffer

	if len(opts) == 0 {
		return &buf
	}

	// Index of sections -> ordered options
	idx := map[string][]*UnitOption{}
	// Separately preserve order in which sections were seen
	sections := []string{}
	for _, opt := range opts {
		sec := opt.Section
		if _, ok := idx[sec]; !ok {
			sections = append(sections, sec)
		}
		idx[sec] = append(idx[sec], opt)
	}

	for i, sect := range sections {
		writeSectionHeader(&buf, sect)
		writeNewline(&buf)

		opts := idx[sect]
		for _, opt := range opts {
			writeOption(&buf, opt)
			writeNewline(&buf)
		}
		if i < len(sections)-1 {
			writeNewline(&buf)
		}
	}

	return &buf
}
275866
function promisify(func) {
        return function(str, options) {
            var result,
                deferred = q.defer(),
                promise = deferred.promise;

            if (!_.isFunction(func)) {
                deferred.reject();
            }
            else {
                result = func(str, options);

                if (_.isBoolean(result)) {
                    promise = handleBoolean(result, deferred);
                }
                else if (_.isFunction(result.then)) {
                    promise = result;
                }

            }
            return promise;
        };
    }
215147
function chaiSupportChainPromise(chai, utils){
    function copyChainPromise(promise, assertion){
        let protoPromise = Object.getPrototypeOf(promise);
        let protoNames = Object.getOwnPropertyNames(protoPromise);
        let protoAssertion = Object.getPrototypeOf(assertion);
        protoNames.forEach(function(protoName){
            if(protoName !== 'constructor' && !protoAssertion[protoName]){
                assertion[protoName] = promise[protoName].bind(promise);
            }
        });
    }
    function doAsserterAsync(asserter, assertion, args){
        let self = utils.flag(assertion, "object");
        if(self && self.then && typeof self.then === "function"){
            let promise = self.then(function(value){
                assertion._obj = value;
                asserter.apply(assertion, args);
                return value;
            }, function(error){
                assertion._obj = new Error(error);
                asserter.apply(assertion, args);
            });
            copyChainPromise(promise, assertion);
        }
        else{
            return asserter.apply(assertion, args);
        }
    }
    let Assertion = chai.Assertion;
    let propertyNames = Object.getOwnPropertyNames(Assertion.prototype);

    let propertyDescs = {};
    propertyNames.forEach(function (name) {
        propertyDescs[name] = Object.getOwnPropertyDescriptor(Assertion.prototype, name);
    });

    let methodNames = propertyNames.filter(function (name) {
        return name !== "assert" && typeof propertyDescs[name].value === "function";
    });

    methodNames.forEach(function (methodName) {
        Assertion.overwriteMethod(methodName, function (originalMethod) {
            return function () {
                doAsserterAsync(originalMethod, this, arguments);
            };
        });
    });

    let getterNames = propertyNames.filter(function (name) {
        return name !== "_obj" && typeof propertyDescs[name].get === "function";
    });

    getterNames.forEach(function (getterName) {
        let isChainableMethod = Assertion.prototype.__methods.hasOwnProperty(getterName);
        if (isChainableMethod) {
            Assertion.overwriteChainableMethod(
                getterName,
                function (originalMethod) {
                    return function() {
                        doAsserterAsync(originalMethod, this, arguments);
                    };
                },
                function (originalGetter) {
                    return function() {
                        doAsserterAsync(originalGetter, this);
                    };
                }
            );
        } else {
            Assertion.overwriteProperty(getterName, function (originalGetter) {
                return function () {
                    doAsserterAsync(originalGetter, this);
                };
            });
        }
    });
}
555901
function createPromisable(wrapped) {
	return function (search, options, callback) {
		var self = this;
		var promisified = Promise.promisify(wrapped, { context: self });
		if (_.isFunction(options)) {
			callback = options;
		}
		if (!_.isFunction(callback)) {
			return {
				promise: function () {
					return promisified(search, options);
				},
				send: function (cb) {
					if (!_.isObject(options)) {
						options = cb;
					}
					wrapped.apply(self, [search, options, cb]);
				}
			};
		} else {
			wrapped.apply(self, [search, options, callback]);
		}
	}
}
260813
function packageProject(cordovaPlatforms, args, /* optional */ projectPath) {
    if (typeof (cordovaPlatforms) == 'string') {
        cordovaPlatforms = [cordovaPlatforms];
    }
    if (!projectPath) {
        projectPath = defaultConfig.projectPath;
    }

    return setupCordova().then(function (cordova) {
        var promise = Q(cordova);
        cordovaPlatforms.forEach(function (platform) {
            if (platform == 'ios') {
                promise = promise.then(function () { return _createIpa(projectPath, args); });
            } else {
                console.log('Platform ' + platform + ' does not require a separate package step.');
            }
        });

        return promise;
    });
}
75286
function(q) {
            // Prepare
            var promises = [],
                loading = 0,
                values = [];
            // Create a new promise to handle all requests
            return pinkyswear(function(pinky) {
                // Basic request method
                var method_index = -1,
                    createMethod = function(method) {
                        return function(url, data, options, before) {
                            var index = ++method_index;
                            ++loading;
                            promises.push(qwest(method, pinky.base + url, data, options, before).then(function(xhr, response) {
                                values[index] = arguments;
                                if(!--loading) {
                                    pinky(true, values.length == 1 ? values[0] : [values]);
                                }
                            }, function() {
                                pinky(false, arguments);
                            }));
                            return pinky;
                        };
                    };
                // Define external API
                pinky.get = createMethod('GET');
                pinky.post = createMethod('POST');
                pinky.put = createMethod('PUT');
                pinky['delete'] = createMethod('DELETE');
                pinky['catch'] = function(f) {
                    return pinky.then(null, f);
                };
                pinky.complete = function(f) {
                    var func = function() {
                        f(); // otherwise arguments will be passed to the callback
                    };
                    return pinky.then(func, func);
                };
                pinky.map = function(type, url, data, options, before) {
                    return createMethod(type.toUpperCase()).call(this, url, data, options, before);
                };
                // Populate methods from external object
                for(var prop in q) {
                    if(!(prop in pinky)) {
                        pinky[prop] = q[prop];
                    }
                }
                // Set last methods
                pinky.send = function() {
                    for(var i=0, j=promises.length; i<j; ++i) {
                        promises[i].send();
                    }
                    return pinky;
                };
                pinky.abort = function() {
                    for(var i=0, j=promises.length; i<j; ++i) {
                        promises[i].abort();
                    }
                    return pinky;
                };
                return pinky;
            });
        }
1075242
function put(key, value, testCacheEnabled) {
  const cacheEnabled = testCacheEnabled || CACHE_ENABLED;

  return postgres.put(key, value)
    .then((res) => {
      // persist to cache only if cache is set up/enabled, return postgres result regardless
      if (cacheEnabled) {
        return redis.put(key, value).then(() => res);
      }

      return res;
    });
}
158557
private SoySauce doCompileSoySauce(
      ServerCompilationPrimitives primitives, Map<String, Supplier<Object>> pluginInstances) {
    Optional<CompiledTemplates> templates =
        BytecodeCompiler.compile(
            primitives.registry,
            primitives.soyTree,
            // if there is an AST cache, assume we are in 'dev mode' and trigger lazy compilation.
            cache != null,
            errorReporter,
            soyFileSuppliers,
            typeRegistry);

    throwIfErrorsPresent();

    return new SoySauceImpl(
        templates.get(),
        scopedData.enterable(),
        soyFunctionMap,
        printDirectives,
        ImmutableMap.copyOf(pluginInstances));
  }