Page MenuHomePhabricator

OO.ui.Process does not support native promises
Closed, ResolvedPublic

Description

The argument to OO.ui.Process() can be a jQuery promise, but not a native promise. This makes Process a bit annoying to use with modern async/await syntax:

new OO.ui.Process(
    async function () {
        throw new Error();
    }
).execute().then(
    () => console.log("success"),
    () => console.log("fail")
);
// logs "success"

Workaround:

new OO.ui.Process( $.when( (
    async function () {
        throw new Error();
    }
)() ) ).execute().then(
    () => console.log("success"),
    () => console.log("fail")
);
// logs "fail"

I think this should be fairly straightforward to fix: in the two places where Process.js checks if typeof something.promise === 'function', check for typeof something.then === 'function' instead and then wrap it in $.when() to turn the Thenable into a jQuery Promise as the rest of the code expects.

Event Timeline

Change 529476 had a related patch set uploaded (by Lucas Werkmeister; owner: Lucas Werkmeister):
[oojs/ui@master] Process: Support any thenable, not just jQuery promise

https://gerrit.wikimedia.org/r/529476

Change 529476 merged by jenkins-bot:
[oojs/ui@master] Process: Support any thenable, not just jQuery promise

https://gerrit.wikimedia.org/r/529476

Change 534517 had a related patch set uploaded (by VolkerE; owner: VolkerE):
[mediawiki/core@master] Update OOUI to v0.34.0

https://gerrit.wikimedia.org/r/534517

Change 534517 merged by jenkins-bot:
[mediawiki/core@master] Update OOUI to v0.34.0

https://gerrit.wikimedia.org/r/534517

LucasWerkmeister claimed this task.

Can confirm that this is fixed in 1.34.0-wmf.22, currently live on Wikimedia Commons.