1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Replace Bluebird.try

This commit is contained in:
Michael Telatynski
2019-11-25 14:22:07 +00:00
parent f8d83f8273
commit fddf2843b4
3 changed files with 17 additions and 7 deletions

View File

@@ -69,7 +69,7 @@ export default class MemoryCryptoStore {
getOrAddOutgoingRoomKeyRequest(request) { getOrAddOutgoingRoomKeyRequest(request) {
const requestBody = request.requestBody; const requestBody = request.requestBody;
return Promise.try(() => { return utils.promiseTry(() => {
// first see if we already have an entry for this request. // first see if we already have an entry for this request.
const existing = this._getOutgoingRoomKeyRequest(requestBody); const existing = this._getOutgoingRoomKeyRequest(requestBody);

View File

@@ -436,7 +436,7 @@ LocalIndexedDBStoreBackend.prototype = {
*/ */
_persistSyncData: function(nextBatch, roomsData, groupsData) { _persistSyncData: function(nextBatch, roomsData, groupsData) {
logger.log("Persisting sync data up to ", nextBatch); logger.log("Persisting sync data up to ", nextBatch);
return Promise.try(() => { return utils.promiseTry(() => {
const txn = this.db.transaction(["sync"], "readwrite"); const txn = this.db.transaction(["sync"], "readwrite");
const store = txn.objectStore("sync"); const store = txn.objectStore("sync");
store.put({ store.put({
@@ -456,7 +456,7 @@ LocalIndexedDBStoreBackend.prototype = {
* @return {Promise} Resolves if the events were persisted. * @return {Promise} Resolves if the events were persisted.
*/ */
_persistAccountData: function(accountData) { _persistAccountData: function(accountData) {
return Promise.try(() => { return utils.promiseTry(() => {
const txn = this.db.transaction(["accountData"], "readwrite"); const txn = this.db.transaction(["accountData"], "readwrite");
const store = txn.objectStore("accountData"); const store = txn.objectStore("accountData");
for (let i = 0; i < accountData.length; i++) { for (let i = 0; i < accountData.length; i++) {
@@ -475,7 +475,7 @@ LocalIndexedDBStoreBackend.prototype = {
* @return {Promise} Resolves if the users were persisted. * @return {Promise} Resolves if the users were persisted.
*/ */
_persistUserPresenceEvents: function(tuples) { _persistUserPresenceEvents: function(tuples) {
return Promise.try(() => { return utils.promiseTry(() => {
const txn = this.db.transaction(["users"], "readwrite"); const txn = this.db.transaction(["users"], "readwrite");
const store = txn.objectStore("users"); const store = txn.objectStore("users");
for (const tuple of tuples) { for (const tuple of tuples) {
@@ -495,7 +495,7 @@ LocalIndexedDBStoreBackend.prototype = {
* @return {Promise<Object[]>} A list of presence events in their raw form. * @return {Promise<Object[]>} A list of presence events in their raw form.
*/ */
getUserPresenceEvents: function() { getUserPresenceEvents: function() {
return Promise.try(() => { return utils.promiseTry(() => {
const txn = this.db.transaction(["users"], "readonly"); const txn = this.db.transaction(["users"], "readonly");
const store = txn.objectStore("users"); const store = txn.objectStore("users");
return selectQuery(store, undefined, (cursor) => { return selectQuery(store, undefined, (cursor) => {
@@ -512,7 +512,7 @@ LocalIndexedDBStoreBackend.prototype = {
logger.log( logger.log(
`LocalIndexedDBStoreBackend: loading account data...`, `LocalIndexedDBStoreBackend: loading account data...`,
); );
return Promise.try(() => { return utils.promiseTry(() => {
const txn = this.db.transaction(["accountData"], "readonly"); const txn = this.db.transaction(["accountData"], "readonly");
const store = txn.objectStore("accountData"); const store = txn.objectStore("accountData");
return selectQuery(store, undefined, (cursor) => { return selectQuery(store, undefined, (cursor) => {
@@ -534,7 +534,7 @@ LocalIndexedDBStoreBackend.prototype = {
logger.log( logger.log(
`LocalIndexedDBStoreBackend: loading sync data...`, `LocalIndexedDBStoreBackend: loading sync data...`,
); );
return Promise.try(() => { return utils.promiseTry(() => {
const txn = this.db.transaction(["sync"], "readonly"); const txn = this.db.transaction(["sync"], "readonly");
const store = txn.objectStore("sync"); const store = txn.objectStore("sync");
return selectQuery(store, undefined, (cursor) => { return selectQuery(store, undefined, (cursor) => {

View File

@@ -737,3 +737,13 @@ module.exports.promiseMapSeries = async (promises, fn) => {
await fn(await o); await fn(await o);
} }
}; };
module.exports.promiseTry = (fn) => {
return new Promise((resolve, reject) => {
try {
fn().then(resolve, reject);
} catch (e) {
reject(e);
}
});
};