From: Bartosz DziewoƄski Date: Tue, 26 Apr 2016 22:16:26 +0000 (+0200) Subject: mediawiki.api: Make the result promise of #postWithToken abortable X-Git-Tag: 1.31.0-rc.0~7048^2 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=4a61bb8fb318f6a086cf4c7e37b9ef9837167ae5;p=lhc%2Fweb%2Fwiklou.git mediawiki.api: Make the result promise of #postWithToken abortable Calling .abort() will abort whichever request is ongoing at the moment. Change-Id: I76acf0f7f270c5d2bd651595a8b9407d37fbb095 --- diff --git a/resources/src/mediawiki/api.js b/resources/src/mediawiki/api.js index 1f21fc6660..f82c26039e 100644 --- a/resources/src/mediawiki/api.js +++ b/resources/src/mediawiki/api.js @@ -288,11 +288,12 @@ * @since 1.22 */ postWithToken: function ( tokenType, params, ajaxOptions ) { - var api = this; + var api = this, + abortable; - return api.getToken( tokenType, params.assert ).then( function ( token ) { + return ( abortable = api.getToken( tokenType, params.assert ) ).then( function ( token ) { params.token = token; - return api.post( params, ajaxOptions ).then( + return ( abortable = api.post( params, ajaxOptions ) ).then( // If no error, return to caller as-is null, // Error handler @@ -301,9 +302,9 @@ api.badToken( tokenType ); // Try again, once params.token = undefined; - return api.getToken( tokenType, params.assert ).then( function ( token ) { + return ( abortable = api.getToken( tokenType, params.assert ) ).then( function ( token ) { params.token = token; - return api.post( params, ajaxOptions ); + return ( abortable = api.post( params, ajaxOptions ) ).promise(); } ); } @@ -311,7 +312,9 @@ return this; } ); - } ); + } ).promise( { abort: function () { + abortable.abort(); + } } ); }, /**