Skip to content

Commit

Permalink
Allow load function return promise
Browse files Browse the repository at this point in the history
  • Loading branch information
taoyuan committed Jan 10, 2018
1 parent 2baf9f6 commit be39402
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/bucket.js
Expand Up @@ -29,10 +29,10 @@ class Bucket {
return cb.promise;
};

get(key, data, cb) {
if (typeof data === 'function') {
cb = data;
data = key;
get(key, query, cb) {
if (typeof query === 'function') {
cb = query;
query = key;
}
cb = cb || utils.createPromiseCallback();
const _key = this.getKey(key);
Expand All @@ -46,7 +46,12 @@ class Bucket {
if (value !== void 0 && (exists || this._allowStale)) {
return value;
}
value = await PromiseA.fromCallback(cb => this._load(data, cb));
if (this._load.length <= 1) {
value = await this._load(query);
} else {
value = await PromiseA.fromCallback(cb => this._load(query, cb));
}

return PromiseA.fromCallback(cb => this.adapter.set(_key, value, cb)).thenReturn(value);
}).asCallback(cb);

Expand Down

0 comments on commit be39402

Please sign in to comment.