Browse Source

add call-me-maybe to ready

Kieran Gibb 2 years ago
parent
commit
91d1c44887
No known key found for this signature in database
3 changed files with 20 additions and 6 deletions
  1. 13
    5
      index.js
  2. 2
    1
      package.json
  3. 5
    0
      yarn.lock

+ 13
- 5
index.js View File

@@ -5,9 +5,9 @@ const path = require('path')
5 5
 const thunky = require('thunky')
6 6
 const debug = require('debug')('cobox-server')
7 7
 const constants = require('cobox-constants')
8
+const maybe = require('call-me-maybe')
8 9
 
9
-const crypto = Crypto()
10
-
10
+const crypto = Crypto() 
11 11
 const { isString } = require('./util')
12 12
 
13 13
 module.exports = (storage, opts) => new GroupStore(storage, opts)
@@ -31,7 +31,16 @@ class GroupStore {
31 31
       return collection
32 32
     }, {})
33 33
 
34
-    this.ready = thunky(this._ready.bind(this))
34
+    this._readyCallback = thunky(this._ready.bind(this))
35
+  }
36
+
37
+  ready (callback) {
38
+    return maybe(callback, new Promise((resolve reject) => {
39
+      this._readyCallback((err) => {
40
+        if (err) return reject(err)
41
+        else resolve()
42
+      })
43
+    }))
35 44
   }
36 45
 
37 46
   all () {
@@ -93,8 +102,7 @@ class GroupStore {
93 102
 
94 103
   // ------------------------------------------------------------------
95 104
 
96
-  _ready (callback) {
97
-    if (!callback) callback = () => {}
105
+  _readyCallback (callback) {
98 106
     var pending = 1
99 107
     var self = this
100 108
 

+ 2
- 1
package.json View File

@@ -12,10 +12,11 @@
12 12
   "author": "magma-collective",
13 13
   "license": "AGPL-3.0-or-later",
14 14
   "dependencies": {
15
+    "call-me-maybe": "^1.0.1",
15 16
     "cobox-config": "git+ssh://git@ledger-git.dyne.org:2240/CoBox/cobox-config.git",
17
+    "cobox-constants": "git+ssh://git@ledger-git.dyne.org:2240/CoBox/cobox-constants.git",
16 18
     "cobox-crypto": "git+ssh://git@ledger-git.dyne.org:2240/CoBox/cobox-crypto.git",
17 19
     "cobox-group": "git+ssh://git@ledger-git.dyne.org:2240/CoBox/cobox-group.git",
18
-    "cobox-constants": "git+ssh://git@ledger-git.dyne.org:2240/CoBox/cobox-constants.git",
19 20
     "debug": "^4.1.1",
20 21
     "thunky": "^1.1.0"
21 22
   },

+ 5
- 0
yarn.lock View File

@@ -229,6 +229,11 @@ byte-stream@^2.1.0:
229 229
     debug "^1.0.4"
230 230
     readable-stream "~1.1.10"
231 231
 
232
+call-me-maybe@^1.0.1:
233
+  version "1.0.1"
234
+  resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.1.tgz#26d208ea89e37b5cbde60250a15f031c16a4d66b"
235
+  integrity sha1-JtII6onje1y95gJQoV8DHBak1ms=
236
+
232 237
 chalk@^1.0.0:
233 238
   version "1.1.3"
234 239
   resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"