Fetches the remote data and fires the callback when it's all complete
@method mixExternal
@param {Callback} cb The callback to execute when complete
@async
335661
function (cb) {
            var self = this,
                info = self.options.external;

            if (!info) {
                cb();
                return;
            }
            if (!info.merge) {
                info.merge = 'mix';
            }
            if (!info.data) {
                Y.log('External config found but no data path defined, skipping import.', 'warn', 'builder');
                cb();
                return;
            }
            if (!Y.Lang.isArray(info.data)) {
                info.data = [info.data];
            }
            Y.log('Importing external documentation data.', 'info', 'builder');

            var stack = new Y.Parallel();
            info.data.forEach(function (i) {
                var base;
                if (i.match(/^https?:\/\//)) {
                    base = i.replace('data.json', '');
                    Y.use('io-base', stack.add(function () {
                        Y.log('Fetching: ' + i, 'info', 'builder');
                        Y.io(i, {
                            on: {
                                complete: stack.add(function (id, e) {
                                    Y.log('Received: ' + i, 'info', 'builder');
                                    var data = JSON.parse(e.responseText);
                                    data.base = base;
                                    //self.options.externalData = Y.mix(self.options.externalData || {}, data);
                                    if (!self.options.externalData) {
                                        self.options.externalData = [];
                                    }
                                    self.options.externalData.push(data);
                                })
                            }
                        });
                    }));
                } else {
                    base = path.dirname(path.resolve(i));
                    var data = Y.Files.getJSON(i);
                    data.base = base;
                    //self.options.externalData = Y.mix(self.options.externalData || {}, data);
                    if (!self.options.externalData) {
                        self.options.externalData = [];
                    }
                    self.options.externalData.push(data);
                }
            });

            stack.done(function () {
                Y.log('Finished fetching remote data', 'info', 'builder');
                self._mixExternal();
                cb();
            });
        }
322238
function(setArr, cb){
            if(typeof setArr === "string")
                var postData = querystring.stringify([setArr]);
            else if(typeof setArr === "object" || typeof setArr === "array")
                var postData = querystring.stringify(setArr);
            
            var options = {
                host: urlArr.hostname,
                path: "/set",
                port: urlArr.port,
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'Content-Length': Buffer.byteLength(postData)
                }
            };
                                    
            var postRequest = protocol.request(options, function(res){
                var result = "";
                
                if(res.statusCode === 200){
                    res.on('error', function(error) {
                        if(typeof cb === "function")
                            cb(error);
                    });
                            
                    res.on('data', function (chunk) {
                        result += chunk;
                    });

                    res.on('end', function (chunk) {
                        if(typeof cb === "function"){
                            var resultObj = JSON.parse(result);
                            var err = (resultObj.status === "error") ? resultObj["msg"] : null;
                            cb(err, resultObj);
                        }    
                    });
                }
                else{
                    if(typeof cb === "function")
                        cb("Request return HTTP "+res.statusCode);
                }
            });
                        
            postRequest.write(postData);
            postRequest.end();
        }
352569
function (cb) {
            if (cb) {
                if (isPromise(cb)) {
                    cb = cb.callback;
                }
                if (this.__fired && this.__results) {
                    this.__callNextTick(cb, this.__results);
                } else {
                    this.__cbs.push(cb);
                }
            }
            return this;
        }
864905
function (options, callback) {
            options = options || {};

            if (options.limit || options.offset) {
                this.$offset = options.offset || 0;
                this.$limit = options.limit || this.$limit;
            }

            var self = this;

            function pageFetchedComplete(err, page, originalCallback) {
                var callback = function (err, page) {
                    if (originalCallback) {
                        originalCallback(err, page, options);
                    }
                };


                if (options.fetchModels || options.fetchSubModels) {

                    // TODO: introduce poolSize parameter for par, and parEach

                    flow()
                        .parEach(page.$items, function (model, cb) {
                            model.fetch({
                                fetchSubModels: options.fetchSubModels
                            }, cb);
                        })
                        .exec(function (err) {
                            callback(err, page);
                        });

                } else {
                    callback(err, page);
                }

            }

            if (this._fetch.state === State.LOADING) {
                // currently fetching -> register callback
                this._fetch.callbacks.push(function (err, page) {
                    pageFetchedComplete(err, page, callback);
                });
            } else if (this._fetch.state == State.LOADED) {
                // completed loaded -> execute
                pageFetchedComplete(null, this, callback);
            } else {
                // set state and start loading
                self._fetch.state = State.LOADING;

                this.$collection.$context.$dataSource.loadCollectionPage(this, options, function (err, page) {
                    self._fetch.state = err ? State.ERROR : State.LOADED;

                    // execute callbacks
                    pageFetchedComplete(err, page, callback);

                    _.each(self._fetch.callbacks, function (cb) {
                        cb(err, page);
                    });
                });
            }
        }
840317
function connect_cb(err, db) {
	if (err) {
	    next(err);
	} else {
	    if (db && db instanceof sqlite) {     // Sqlite only
		app.db = db;
		// Use the query escaping facilities of mysql
		app.db.escape = SqliteString.escape;
		app.db.escapeId = SqliteString.escapeId;
		app.db.format = SqliteString.format;
		// Wrap exec with a signature similar to mysql's
		// prepared queries
		app.db.query = function(sql, values, callback) {
		    // prepare the statement
		    if (typeof values == 'function') {
			callback = values;
		    } else {
			sql = app.db.format(sql, values);
		    }
		    // Log some info
		    console.log('SQL query:', sql);
		    // execute the statement
		    app.db.exec(sql, callback);
		};
		app.db.end = function() {};
	    } else {                              // MySql only
		app.db.format = MySqlString.format;
		// Wrap qyery with some logging some logging 
		var _query = app.db.query;
		app.db.query = function(sql, values, callback) {
		    var _sql = sql;
		    // prepare the statement (just for logging)
		    if (typeof values != 'function')
			_sql = app.db.format(sql, values);
		    // Log some info
		    console.log('SQL query:', _sql);
		    // execute the statement
		    return _query.call(this, sql, values, callback);
		};
	    }
	    next();
	}
    }
703674
function(params, cb) {
    var correlationId = _cbt.put(offFetchResponse(cb));
    var msg = envelope(offFetch.encode(params.fetchFromCoordinator ? 1 : 0)
                               .correlation(correlationId)
                               .client(_options.clientId)
                               .group(params.group)
                               .topic(params.topic)
                               .partition(params.partition)
                               .end());
    sendMsg(msg, correlationId, cb);
  }
1034401
function ensureConnected(remote, callback) {
  if (remote.getServer()) {
    callback(null, isConnected(remote));
  } else {
    callback(null, false);
  }
}
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;
  }
882442
function download(url, dest, cb) {
  var reportError = function(err) {
    var timeoutMessge;

    if (err.code === 'ETIMEDOUT') {
      if (err.connect === true) {
        // timeout is hit while your client is attempting to establish a connection to a remote machine
        timeoutMessge = 'Timed out attemping to establish a remote connection';
      } else {
        timeoutMessge = 'Timed out whilst downloading the prebuilt binary';
        // occurs any time the server is too slow to send back a part of the response
      }

    }
    cb(['Cannot download "', url, '": ', eol, eol,
      typeof err.message === 'string' ? err.message : err, eol, eol,
      timeoutMessge ? timeoutMessge + eol + eol : timeoutMessge,
      'Hint: If github.com is not accessible in your location', eol,
      '      try setting a proxy via HTTP_PROXY, e.g. ', eol, eol,
      '      export HTTP_PROXY=http://example.com:1234',eol, eol,
      'or configure npm proxy via', eol, eol,
      '      npm config set proxy http://example.com:8080'].join(''));
  };

  var successful = function(response) {
    return response.statusCode >= 200 && response.statusCode < 300;
  };

  console.log('Downloading binary from', url);

  try {
    request(url, downloadOptions(), function(err, response, buffer) {
      if (err) {
        reportError(err);
      } else if (!successful(response)) {
        reportError(['HTTP error', response.statusCode, response.statusMessage].join(' '));
      } else {
        console.log('Download complete');

        if (successful(response)) {
          fs.createWriteStream(dest)
            .on('error', cb)
            .end(buffer, cb);
        } else {
          cb();
        }
      }
    })
    .on('response', function(response) {
      var length = parseInt(response.headers['content-length'], 10);
      var progress = log.newItem('', length);

      // The `progress` is true by default. However if it has not
      // been explicitly set it's `undefined` which is considered
      // as far as npm is concerned.
      if (process.env.npm_config_progress === 'true') {
        log.enableProgress();

        response.on('data', function(chunk) {
          progress.completeWork(chunk.length);
        })
        .on('end', progress.finish);
      }
    });
  } catch (err) {
    cb(err);
  }
}
1044611
def make_call_with_cb(self, fun, *args):
        """"""

        cid, event = self.handler.register_callback()
        argscp = list(args)
        argscp.append(cid)
        self.make_call(fun, *argscp)
        return event
1337356
function(params, cb, oldscope) {
		query.params = params;
		// Note the callback function has the data and error reversed due to existing code in promiseExec which has the
		// err and data swapped.  This trickles down into alasql.exec and further. Rather than risk breaking the whole thing,
		// the (data, err) standard is maintained here.
		var res1 = queryfn(query, oldscope, function(res, err) {
			if (err) {
				return cb(err, null);
			}
			if (query.rownums.length > 0) {
				for (var i = 0, ilen = res.length; i < ilen; i++) {
					for (var j = 0, jlen = query.rownums.length; j < jlen; j++) {
						res[i][query.rownums[j]] = i + 1;
					}
				}
			}

			var res2 = modify(query, res);

			if (cb) {
				cb(res2);
			}
			//console.log(8888,res2);
			return res2;
		});
		//console.log(9999,res1);

		//		if(typeof res1 != 'undefined') res1 =  modify(query,res1);

		return res1;
	}
1162999
function(command, callback) {
    var self = this;
    return new Promise(function(resolve, reject) {
        var prCB = function(err, data) {
          if (err) {
            log.error(err.message);
            log.debug(command);
          }
          return (err ? reject('err') : resolve(data));
        };
        self.connection.execute(command, function(err, result) {
          prCB(err, result)
        });
    });
  }
376116
function( url, cb ) {
		var xhr = new window.XMLHttpRequest();
		if ( "withCredentials" in xhr ) {
			xhr.open( "GET", url, true );
		} else if ( typeof window.XDomainRequest !== "undefined" ) { //IE
			xhr = new window.XDomainRequest();
			xhr.open( "GET", url );
		}
		if( cb ){
			xhr.onload = cb;
		}
		xhr.send();
		return xhr;
	}
1334748
function listen(port, cb) {
    return new Promise((resolve, reject) => {
        let completed = ssocket_helpers.createSimplePromiseCompletedAction(resolve, reject);
        try {
            let serverToClient;
            let server = Net.createServer((connectionWithClient) => {
                try {
                    if (cb) {
                        cb(null, createServer(connectionWithClient));
                    }
                }
                catch (e) {
                    if (cb) {
                        cb(e);
                    }
                }
            });
            let isListening = false;
            server.once('error', (err) => {
                if (!isListening && err) {
                    completed(err);
                }
            });
            server.on('listening', () => {
                isListening = true;
                completed(null, server);
            });
            server.listen(port);
        }
        catch (e) {
            completed(e);
        }
    });
}
871428
function (url, cb) {

            var request = new XMLHttpRequest();

            request.onload = function () {
                if (this.status >= 200 && this.status < 400) {
                    cb(this.response);
                }
                else {
                    Logger.log(Logger.LEVEL_SEVERE, "sever error: " + this.status);
                    cb(null);
                }
            };

            request.onerror = function (e) {
                Logger.log(Logger.LEVEL_SEVERE, "connection error: " + e);
                cb(null);
            };

            request.open("get", url, true);

            request.send();
        }
813680
function(data, cb) {
                if (corbel.Config.isNode) {
                    // in node transform to stream
                    cb(corbel.utils.toURLEncoded(data));
                } else {
                    // in browser transform to blob
                    cb(corbel.utils.dataURItoBlob(data));
                }
            }
771898
function(url, dest, cb) {
      var get = request(url);
      get.on('response',  function (res) {
        res.pipe(fs.createWriteStream(dest));
        res.on('end', function () {
          cb();
        });
        res.on('error', function (err) {
          cb(err);
        });
      });
    }