提交 494b7b7d 编写于 作者: A Alex Dima

Bring "hidden" code out in the open

上级 748ceac1
......@@ -8,7 +8,58 @@ import platform = require('vs/base/common/platform');
import types = require('vs/base/common/types');
import { IAction } from 'vs/base/common/actions';
import Severity from 'vs/base/common/severity';
import { TPromise } from 'vs/base/common/winjs.base';
import { TPromise, IPromiseError, IPromiseErrorDetail } from 'vs/base/common/winjs.base';
// ------ BEGIN Hook up error listeners to winjs promises
let outstandingPromiseErrors: { [id: string]: IPromiseErrorDetail; } = {};
function promiseErrorHandler(e: IPromiseError): void {
//
// e.detail looks like: { exception, error, promise, handler, id, parent }
//
var details = e.detail;
var id = details.id;
// If the error has a parent promise then this is not the origination of the
// error so we check if it has a handler, and if so we mark that the error
// was handled by removing it from outstandingPromiseErrors
//
if (details.parent) {
if (details.handler && outstandingPromiseErrors) {
delete outstandingPromiseErrors[id];
}
return;
}
// Indicate that this error was originated and needs to be handled
outstandingPromiseErrors[id] = details;
// The first time the queue fills up this iteration, schedule a timeout to
// check if any errors are still unhandled.
if (Object.keys(outstandingPromiseErrors).length === 1) {
setTimeout(function () {
var errors = outstandingPromiseErrors;
outstandingPromiseErrors = {};
Object.keys(errors).forEach(function (errorId) {
var error = errors[errorId];
if (error.exception) {
onUnexpectedError(error.exception);
} else if (error.error) {
onUnexpectedError(error.error);
}
console.log('WARNING: Promise with no error callback:' + error.id);
console.log(error);
if (error.exception) {
console.log(error.exception.stack);
}
});
}, 0);
}
}
TPromise.addEventListener('error', promiseErrorHandler);
// ------ END Hook up error listeners to winjs promises
export interface ErrorListenerCallback {
(error: any): void;
......
......@@ -55,6 +55,18 @@ export interface TProgressCallback<T> {
(progress: T): void;
}
interface IPromiseErrorDetail {
parent: TPromise<any>;
error: any;
id: number;
handler: Function;
exception: Error;
}
interface IPromiseError {
detail: IPromiseErrorDetail;
}
/**
* A Promise implementation that supports progress and cancelation.
*/
......@@ -95,6 +107,11 @@ export declare class TPromise<V> {
public static wrap<ValueType>(value: ValueType): TPromise<ValueType>;
public static wrapError<ValueType>(error: any): TPromise<ValueType>;
/**
* @internal
*/
public static addEventListener(event: 'error', promiseErrorHandler: (e: IPromiseError) => void);
}
// --- Generic promise with generic progress value
......
......@@ -3,60 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
define(['./winjs.base.raw', 'vs/base/common/errors'], function (winjs, __Errors__) {
define(['./winjs.base.raw'], function (winjs) {
'use strict';
var outstandingPromiseErrors = {};
function promiseErrorHandler(e) {
//
// e.detail looks like: { exception, error, promise, handler, id, parent }
//
var details = e.detail;
var id = details.id;
// If the error has a parent promise then this is not the origination of the
// error so we check if it has a handler, and if so we mark that the error
// was handled by removing it from outstandingPromiseErrors
//
if (details.parent) {
if (details.handler && outstandingPromiseErrors) {
delete outstandingPromiseErrors[id];
}
return;
}
// Indicate that this error was originated and needs to be handled
outstandingPromiseErrors[id] = details;
// The first time the queue fills up this iteration, schedule a timeout to
// check if any errors are still unhandled.
if (Object.keys(outstandingPromiseErrors).length === 1) {
setTimeout(function () {
var errors = outstandingPromiseErrors;
outstandingPromiseErrors = {};
Object.keys(errors).forEach(function (errorId) {
var error = errors[errorId];
if(error.exception) {
__Errors__.onUnexpectedError(error.exception);
} else if(error.error) {
__Errors__.onUnexpectedError(error.error);
}
console.log("WARNING: Promise with no error callback:" + error.id);
console.log(error);
if(error.exception) {
console.log(error.exception.stack);
}
});
}, 0);
}
}
winjs.Promise.addEventListener("error", promiseErrorHandler);
return {
Promise: winjs.Promise,
TPromise: winjs.Promise,
PPromise: winjs.Promise
};
});
\ No newline at end of file
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册