switch from Q to Bluebird

This commit is contained in:
Matteo Pagliazzi
2016-05-11 14:34:01 +02:00
parent 299ed624f5
commit cee7700a50
43 changed files with 230 additions and 201 deletions

View File

@@ -1,9 +1,9 @@
import { exec } from 'child_process';
import psTree from 'ps-tree';
import nconf from 'nconf';
import net from 'net';
import Q from 'q';
import { post } from 'superagent';
import { exec } from 'child_process';
import psTree from 'ps-tree';
import nconf from 'nconf';
import net from 'net';
import Bluebird from 'bluebird';
import { post } from 'superagent';
import { sync as glob } from 'glob';
import Mocha from 'mocha';
import { resolve } from 'path';
@@ -43,25 +43,24 @@ export function kill(proc) {
* has fully spun up. Optionally provide a maximum number of seconds to wait
* before failing.
*/
export function awaitPort(port, max=60) {
let socket, timeout, interval;
let deferred = Q.defer();
export function awaitPort (port, max=60) {
return new Bluebird((reject, resolve) => {
let socket, timeout, interval;
timeout = setTimeout(() => {
clearInterval(interval);
deferred.reject(`Timed out after ${max} seconds`);
}, max * 1000);
interval = setInterval(() => {
socket = net.connect({port: port}, () => {
timeout = setTimeout(() => {
clearInterval(interval);
clearTimeout(timeout);
socket.destroy();
deferred.resolve();
}).on('error', () => { socket.destroy });
}, 1000);
reject(`Timed out after ${max} seconds`);
}, max * 1000);
return deferred.promise
interval = setInterval(() => {
socket = net.connect({port: port}, () => {
clearInterval(interval);
clearTimeout(timeout);
socket.destroy();
resolve();
}).on('error', () => { socket.destroy });
}, 1000);
});
};
/*