Skip to content

WinJS.Promise removal plan #53526

@jrieken

Description

@jrieken

We are heavy users of WinJS.Promise and that's not good. We started with the monaco-editor before native promises existed, so WinJS.Promises came in handy. However, times have changed, native promises are real and sticking with WinJS.Promises became a dead end. Time for change...

Migrating from WinJS.Promise to the native promises isn't a find/replace-job because of some incompatibilities, namely the runtime-behaviour and different APIs. In a first wave we want to focus on two elephants:

In more detail

WinJS.Promise#cancel

Calling winjsPromise.cancel() does two things: (1) it calls a cancel-handler that you provide when constructing a winjs-promise and (2) it puts the promise in the rejected-state with a cancelled-error.

The native promise doesn't support cancellation and it needs to be replaced it with our own solution. For extensions we already offer CancellationTokenSource and CancellationToken and we want to adopt it for "internal" use too. It's important to know that a cancellation token is just a hint and that a consumer might ignore it and proceed as before. In contrast to the winjs-promise-behaviour that means you must not end-up in the rejection-handler but you might end-up in the success-handler. That's fine as long as you can handle it.

Because all of our code is written (and tested) with the winjs-promise-behaviour in mind we have added a util that makes adoption easy: CancelablePromise and createCancelablePromise. Checkout the initial commit to understand how to use it: https://github.com//Microsoft/vscode/commit/727c6f3537d732269db30cbb9efd496073351586. The contract is that calling cancel puts the promise into the rejected-state using the well-known cancelled-error.

onProgress

The then-function of winjs-promises can accept three callbacks and the latter is used for progress events. Those can fire multiple times during promise execution. Again, nothing the native promise supports and something we need to replace with our own code. There is PR in which this effort is tracked: #53487

Differences in runtime behaviour

The winjs-promise shows different runtime behaviour then native promises and when switching to native promises you should be aware of that. In contract to native promises, a winjs-promise that is resolved in its executor-function calls its then-handlers immediately. Check with these tests that outline the differences: https://github.com/Microsoft/vscode/blob/11c5b9381b8d1db012055201d48cc4d37299afce/src/vs/base/test/common/winjs.polyfill.promise.test.ts#L36

Metadata

Metadata

Labels

debtCode quality issuesengineeringVS Code - Build / issue tracking / etc.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions