git ssb

1+

Daan Patchwork / manyverse



Commit 77efc47483168400924331091bca4758b8356f63

ux: fix bug, race condition with ssbKeys.loadOrCreate

Andre Staltz committed on 8/22/2018, 7:55:58 PM
Parent: 007754bbd9e9c054718db522b27ba4d63b80f17c

Files changed

src/app/drivers/ssb.tschanged
src/worker/index.tschanged
src/app/drivers/ssb.tsView
@@ -246,9 +246,11 @@
246246 return {type: 'publish', content};
247247 }
248248
249249 export function ssbDriver(sink: Stream<Req>): SSBSource {
250- const keys$ = xsFromCallback(ssbKeys.loadOrCreate)(ssbKeysPath);
250+ const keys$ = xs
251+ .throw(new Error('keep retrying ssbKeys.load() until it works'))
252+ .replaceError(() => xsFromCallback(ssbKeys.load)(ssbKeysPath));
251253
252254 const api$ = keys$
253255 .take(1)
254256 .compose(dropCompletion)
src/worker/index.tsView
@@ -32,14 +32,18 @@
3232 const createClient = require('ssb-client');
3333
3434 const ms = MultiServer([workerPlugin({worker: self})]);
3535
36-const keysPromise = new Promise((resolve, reject) => {
37- ssbKeys.loadOrCreate(ssbKeysPath, (err: any, keys: any) => {
38- if (err) {
39- reject(err);
40- } else if (keys) {
36+const keysPromise = new Promise(resolve => {
37+ let retryPeriod = 400;
38+ ssbKeys.load(ssbKeysPath, function done(err: any, keys: any) {
39+ if (!err && keys) {
4140 resolve(keys);
41+ } else {
42+ setTimeout(() => {
43+ retryPeriod *= 2;
44+ ssbKeys.load(ssbKeysPath, done);
45+ }, retryPeriod);
4246 }
4347 });
4448 });
4549

Built with git-ssb-web