Skip to content

Commit

Permalink
Merge pull request #25 from QubitProducts/ungen
Browse files Browse the repository at this point in the history
Use promises instead of generators
  • Loading branch information
oliverwoodings authored Dec 7, 2016
2 parents f6b3fc2 + 0704e52 commit 69c704f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/cached.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function cached (namespace, producer, timeout) {
CACHE[namespace] = {}
var cache = CACHE[namespace]

return co(function * () {
return function () {
var args = Array.prototype.slice.call(arguments)
var key = args.join(SEPARATOR)

Expand Down Expand Up @@ -46,5 +46,5 @@ module.exports = function cached (namespace, producer, timeout) {
}

return cloneDeep(cache[key].val) || cache[key].fetch
})
}
}
9 changes: 5 additions & 4 deletions lib/getCurrent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var co = require('creed').coroutine

module.exports = co(function * getCurrent (s3, branch) {
var current = yield s3.tryReadingFile(`/${branch}/current`)
return current ? current.Body.toString() : null
})
module.exports = function getCurrent (s3, branch) {
return s3.tryReadingFile(`/${branch}/current`).then(function (current) {
return current ? current.Body.toString() : null
})
}
10 changes: 4 additions & 6 deletions lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ S3FS.prototype.readdir = function () {

// extend S3FS with a function that attempts reading the file, but
// handles not found case without throwing
S3FS.prototype.tryReadingFile = co(function * tryReadFile (path) {
try {
return yield this.readFile(path)
} catch (err) {
S3FS.prototype.tryReadingFile = function tryReadFile (path) {
return this.readFile(path).catch(function (err) {
if (err.code !== 'NoSuchKey') {
throw err
}
}
})
})
}

module.exports = function (bapConfig) {
return new S3FS(bapConfig.bucket, {
Expand Down

0 comments on commit 69c704f

Please sign in to comment.