diff --git a/src/components/structures/ScrollPanel.js b/src/components/structures/ScrollPanel.js index 95ab586e03..a8a2ec181b 100644 --- a/src/components/structures/ScrollPanel.js +++ b/src/components/structures/ScrollPanel.js @@ -386,19 +386,12 @@ module.exports = React.createClass({ debuglog("ScrollPanel: starting "+dir+" fill"); // onFillRequest can end up calling us recursively (via onScroll - // events) so make sure we set this before firing off the call. That - // does present the risk that we might not ever actually fire off the - // fill request, so wrap it in a try/catch. + // events) so make sure we set this before firing off the call. this._pendingFillRequests[dir] = true; - var fillPromise; - try { - fillPromise = this.props.onFillRequest(backwards); - } catch (e) { - this._pendingFillRequests[dir] = false; - throw e; - } - q.finally(fillPromise, () => { + Promise.try(() => { + return this.props.onFillRequest(backwards); + }).finally(() => { this._pendingFillRequests[dir] = false; }).then((hasMoreResults) => { if (this.unmounted) { diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 3cc0b40686..c5791aa933 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -568,15 +568,16 @@ module.exports = React.createClass({ }); // reject the invites const promises = rooms.map((room) => { - return MatrixClientPeg.get().leave(room.roomId); + return MatrixClientPeg.get().leave(room.roomId).catch((e) => { + // purposefully drop errors to the floor: we'll just have a non-zero number on the UI + // after trying to reject all the invites. + }); }); - // purposefully drop errors to the floor: we'll just have a non-zero number on the UI - // after trying to reject all the invites. - q.allSettled(promises).then(() => { + Promise.all(promises).then(() => { this.setState({ rejectingInvites: false, }); - }).done(); + }); }, _onExportE2eKeysClicked: function() { diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index addd1f2e7f..387aca2fa5 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -183,6 +183,12 @@ module.exports = React.createClass({ }); }, + /** + * Returns a promise which resolves once all of the save operations have completed or failed. + * + * The result is a list of promise state snapshots, each with the form + * `{ state: "fulfilled", value: v }` or `{ state: "rejected", reason: r }`. + */ save: function() { var stateWasSetDefer = Promise.defer(); // the caller may have JUST called setState on stuff, so we need to re-render before saving @@ -194,8 +200,18 @@ module.exports = React.createClass({ this.setState({ _loading: false}); }); + function mapPromiseToSnapshot(p) { + return p.then((r) => { + return { state: "fulfilled", value: r }; + }, (e) => { + return { state: "rejected", reason: e }; + }); + } + return stateWasSetDefer.promise.then(() => { - return q.allSettled(this._calcSavePromises()); + return Promise.all( + this._calcSavePromises().map(mapPromiseToSnapshot), + ); }); },