Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function delay(continuation) {
return when.promise(function(resolve){
delegationFunction(resolve);
}).then(continuation);
}
// Allow the caller to specify a failure logger function, to which all intermediate errors will be passed.
var findDevice = function(deviceName, ttl) {
return promise(function(resolve, reject) {
var scanner = mdns.createBrowser(mdns.tcp('googlecast'));
if (!ttl) ttl = 10000; // default to 10 seconds
var timer = setTimeout(function() {
scanner.stop();
reject('device not found');
}, ttl);
scanner.on('serviceUp', function(service) {
if (deviceName && deviceName !== service.name) return;
resolve(service);
scanner.stop();
clearTimeout(timer);
});
scanner.start();
});
};
_loadView (service, route, routeStr) {
// add promise wrapper
return when.promise(function (resolve, reject) {
// ------------------------------------------------
var templateMiddleware, templateDefaultMW;
if (!route.hasOwnProperty('template')) {
service.logger.warn('Template missing from route view', routeStr);
return;
}
// get all 'template' middleware
templateMiddleware = this._middleware.getAll('template');
templateDefaultMW = this._middleware.getDefault('template');
if (!Object.keys(templateMiddleware).length || !templateDefaultMW) {
// load default templates
this._middleware.install([{
group: 'template',
name: 'ejs',
function after() {
var promise = when.promise(function(resolve, reject) {
test.ok(java.isJvmCreated());
resolve();
});
return promise;
}
function before() {
var promise = when.promise(function(resolve, reject) {
test.ok(!java.isJvmCreated());
resolve();
});
return promise;
}
export function getLinks(page) {
return promise((resolve, reject) => {
request.get(`${url}${page}`).end((err, res) => {
if (err) {
reject(err);
} else {
resolve(JSON.parse(res.text));
}
});
});
}
function shrink(image, maxWidth, maxHeight) {
return when.promise(function(resolve, reject) {
var canvas = document.createElement('canvas');
var img = new Image();
img.onload = function() {
var MAX_WIDTH = maxWidth;
var MAX_HEIGHT = maxHeight;
var width = img.width;
var height = img.height;
if (width > height) {
if (width > MAX_WIDTH) {
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
}
} else {
if (height > MAX_HEIGHT) {
width *= MAX_HEIGHT / height;
function writeFile(path, content) {
return when.promise(function writeFilePromiseFn(resolve, reject) {
var stream = fs.createWriteStream(path);
stream.on('open', function writeFileStreamOpenFn(fd) {
stream.end(content, 'utf8', function writeFileStreamEndFn() {
fs.fsync(fd, resolve);
});
});
stream.on('error', function writeFileStreamErrorFn(err) {
reject(err);
});
});
}
function setSCK(){
return when.promise(function(resolve, reject) {
tinyAVR.setSCK(function(err){
if(err){ return reject(err); }
return resolve();
});
});
}
var callRemoteService = function callRemoteService() {
return when.promise(function(resolve, reject) {
setTimeout(function() {
if (_.random(0, 10) < 3) {
return reject(new Error('Incorrect arguments supplied'));
}
return resolve();
});
});
};