From 9581b4ef31e78f9b272c49b9c97c442b3e6a8146 Mon Sep 17 00:00:00 2001 From: haad Date: Fri, 8 Apr 2016 08:56:56 +0200 Subject: [PATCH] Replace async/await with Promises where possible --- examples/benchmark.js | 2 +- src/Client.js | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/benchmark.js b/examples/benchmark.js index 0c04b20..ef44627 100644 --- a/examples/benchmark.js +++ b/examples/benchmark.js @@ -50,7 +50,7 @@ let run = (async(() => { // let timer = new Timer(); // while(true) { // timer.start(); - db.add(username + totalQueries); + await(db.add(username + totalQueries)); // console.log(`${timer.stop(true)} ms`); totalQueries ++; lastTenSeconds ++; diff --git a/src/Client.js b/src/Client.js index ac71d7a..fb684c6 100644 --- a/src/Client.js +++ b/src/Client.js @@ -22,12 +22,11 @@ class Client { if(password === undefined) password = ''; if(subscribe === undefined) subscribe = true; - this.db.use(channel, this.user, password).then(() => { - this.db.events[channel].on('write', this._onWrite.bind(this)); - this.db.events[channel].on('sync', this._onSync.bind(this)); - this.db.events[channel].on('load', this._onLoad.bind(this)); - this.db.events[channel].on('loaded', this._onLoaded.bind(this)); - }); + await(this.db.use(channel, this.user, password)); + this.db.events[channel].on('write', this._onWrite.bind(this)); + this.db.events[channel].on('sync', this._onSync.bind(this)); + this.db.events[channel].on('load', this._onLoad.bind(this)); + this.db.events[channel].on('loaded', this._onLoaded.bind(this)); if(subscribe) this._pubsub.subscribe(channel, password, async((channel, message) => this.db.sync(channel, message)));