Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
waitForTimeout: function() {
// The auto-export is not done if the timeout is set to zero (or less).
// This is useful in cases where the export is done manually through
// API exposed to the content.
let timeout = Services.prefs.getIntPref(
"devtools.netmonitor.har.pageLoadedTimeout");
trace.log("HarCollector.waitForTimeout; " + timeout);
this.pageLoadDeferred = defer();
if (timeout <= 0) {
this.pageLoadDeferred.resolve();
return this.pageLoadDeferred.promise;
}
this.pageLoadTimeout = setTimeout(this.onPageLoadTimeout, timeout);
return this.pageLoadDeferred.promise;
},
exports.Broadcaster = function(path, subscriptionApp, nextApp){
if(request.pathInfo !== path){
return nextApp(request);
}
var clientConnection = request.clientConnection;
clientConnection.previous && (clientConnection.previous.next = clientConnection.next);
clientConnection.next && (clientConnection.next.previous = clientConnection.previous);
if(!clientConnection){
clientConnection = request.clientConnection = [];
}
subscriptionApp(request); // ignore the response
if(clientConnection.length){
return sendAllMessages();
}else{
var deferred = defer(function(){
clientConnection.onClose && clientConnection.onClose();
});
clientConnection.onMessages = function(message){
clientConnection.lastTouched = new Date().getTime();
if(mostRecentlyUsed){
mostRecentlyUsed.next = clientConnection;
clientConnection.previous = mostRecentlyUsed;
}
mostRecentlyUsed = clientConnection;
delete clientConnection.onMessages;
// TODO: maybe queue this up for the next event turn
deferred.resolve(drain());
};
return deferred.promise;
}
function sendAllMessages(){
exports["test reject"] = function () {
var deferred = promiseModule.defer();
var promise = deferred.promise;
var reject = deferred.reject;
var ok, error;
promiseModule.when(promise, function (value) {
ok = value;
}, function (exception) {
error = exception;
});
reject(new Error("result"));
processEvents();
assert.ok(!ok);
assert.ok(error);
actions[i] = function(value){
var deferred = promiseModule.defer();
deferred.resolve(value + 1);
return deferred.promise;
}
}
exports["test ref_send API resolve->when"] = function () {
var deferred = promiseModule.defer();
var promise = deferred.promise;
var resolve = deferred.resolve;
resolve("result");
var ok, error;
promiseModule.when(promise, function (value) {
ok = value;
}, function (exception) {
error = exception;
});
processEvents();
assert.ok(ok);
assert.ok(!error);
async _queuedProcess(callback: (worker: WorkerDelegate) => Promise): Promise {
const currentWorker = this.transformWorkers.find(worker => worker.busyProcessing === 0)
let promise
if (currentWorker) {
promise = callback(currentWorker)
} else {
const { promise: deferredPromise, resolve, reject } = promiseDefer()
this.workersQueue.push(worker => {
callback(worker).then(resolve, reject)
})
promise = deferredPromise
}
return promise
}
async initialize() {
Require.read = function (url) {
var request = new XMLHttpRequest();
var response = Promise.defer();
function onload() {
if (xhrSuccess(request)) {
response.resolve(request.responseText);
} else {
onerror();
}
}
function onerror() {
response.reject(new Error("Can't XHR " + JSON.stringify(url)));
}
try {
request.open(GET, url, true);
if (request.overrideMimeType) {