1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2026-01-03 23:22:30 +03:00

Use once to clean up listener

This commit is contained in:
David Baker
2017-04-07 11:10:57 +01:00
parent 18806e5524
commit cfff30c314

View File

@@ -13,9 +13,14 @@ const MatrixEvent = sdk.MatrixEvent;
*/
module.exports.syncPromise = function(client) {
const def = q.defer();
client.on('sync', (state) => {
if (state == 'SYNCING') def.resolve();
});
const cb = (state) => {
if (state == 'SYNCING') {
def.resolve();
} else {
client.once('sync', cb);
}
};
client.once('sync', cb);
return def.promise;
};