Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
add : function(props) {
var self = this;
var def = when.defer();
var checkExistance = when.defer();
var tagDef = when.defer();
try {
// if we have an original url, make sure it's a url
if (props.original_url && props.original_url.length) {
assert(Validator.isURL(props.original_url), "original_url isn't a URL");
// check if this already exists, based on URL. if it does, exit.
self.forge({ original_url : props.original_url }).fetch().then(function(submission) {
console.log(submission);
if (typeof submission !== "undefined" && submission !== null) {
checkExistance.reject("This example already exists. Id " + submission.id);
} else {
checkExistance.resolve();
}
});
Session.prototype.register = function (endpoint, procedure, options) {
var self = this;
// create an remember new REGISTER request
//
var request = newid();
var d = when.defer();
self._register_reqs[request] = [d, endpoint, options];
// construct REGISTER message
//
var msg = [MSG_TYPE.REGISTER, request];
if (options) {
msg.push(options);
} else {
msg.push({});
}
msg.push(procedure);
// send WAMP message
//
self._send_wamp(msg);
createDeferred: function(callback) {
var deferred = when.defer();
if (callback) {
// Callback, if provided, is a simply translated to Promise'esque:
// (Ensure callback is called outside of promise stack)
deferred.promise.then(function(res) {
setTimeout(function(){ callback(null, res) }, 0);
}, function(err) {
setTimeout(function(){ callback(err, null); }, 0);
});
}
return deferred;
},
var when = require('when');
var deferred = when.defer();
StopDetails.prototype.fetch = function() {
var deferred = when.defer();
var yqlURL = 'http://query.yahooapis.com/v1/public/yql';
var capURL = 'https://www.capmetro.org/planner/s_nextbus2.asp?stopid=' + this.stopID() + '&route=' + this.routeID();
var params = {
q: 'select * from xml where url="' + capURL + '"',
format: 'json'
};
this.errorMsg(null);
function retryAtMost(maxRetries) {
requests.get(yqlURL, params)
.then(this.parseResponse.bind(this))
.tap(function(Runs) {
if (Runs.length > 0) {
this.tripCollection = new TripCollection(this.stopID(), this.routeID(), Runs);
}
function readStream(stream, numBytes){
var deferred = when.defer();
var data = stream.read(numBytes);
if(data){
deferred.resolve(data);
}else{
stream.once && stream.once('readable', function(){
var promise = readStream(stream, numBytes);
promise.then(function(data){
deferred.resolve(data);
});
});
}
return deferred.promise;
}
readString(path) {
const stream = this.read(path)
const dfd = when.defer()
let buf = ''
stream.on('data', d => buf += d.toString())
stream.on('error', err => dfd.reject(err))
stream.on('end', () => dfd.resolve(buf))
return dfd.promise
}
/**
* Created by nboseman on 2/11/14.
*/
var schemas = require('../../../dao/schemas');
var mongoose = require('mongoose');
var ruleViolation = require('../ruleviolation');
var when = require('when');
var deferred = when.defer();
var rule = null;
var evaluateUniqueId = function(feedId, constraintSet, ruleDefinition){
var when = require('when');
rule = ruleDefinition;
var finds = [];
constraintSet.entity.forEach(function(model) {
Model = mongoose.model(model);
finds.push(Model.find({ '_feed': feedId },{'elementId':1,'_feed':1}).exec());
}, this);
when.all(finds)
.then(processQueryResults, errorHandler);
then: function( success, failure ) {
var deferred = when.defer();
function onSuccess( result ) {
deferred.resolve( result );
}
function onFailure( error ) {
deferred.reject( error );
}
this.end( onSuccess );
this.error( onFailure );
return deferred.promise
.then( success, failure );
},
static getEvent(eventName, tournamentName, options={}){
let deferred = when.defer();
try{
let E = new Event(eventName, tournamentName, options);
E.on('ready', function(){
deferred.resolve(E);
});
E.on('error', function(e){
log.error('getEvent error: %s', e);
deferred.reject(e);
});
} catch(e){
log.error('getEvent error: %s', e);
deferred.reject(e);
}
return deferred.promise;
}