Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) Treat updateNotify async #67

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ipc/sidecar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const parse = require('../lib/parse')
const { discoveryKey } = require('hypercore-crypto')
const { isWindows, isMac } = require('which-runtime')
const { SWAP, INTERNAL_UNSAFE, SPINDOWN_TIMEOUT, DESKTOP_RUNTIME, SOCKET_PATH, PLATFORM_DIR } = require('../lib/constants')
const safetyCatch = require('safety-catch')

const { constructor: AGF } = async function * () {}

Expand All @@ -30,7 +31,8 @@ module.exports = class IPC {
constructor ({ updater, drive, corestore }) {
this.updater = updater
if (this.updater) {
this.updater.on('update', (checkout) => this.updateNotify(checkout))
// TODO: await and debounce?
this.updater.on('update', (checkout) => this.updateNotify(checkout).catch(safetyCatch))
}

this.server = Pipe.createServer()
Expand Down
11 changes: 8 additions & 3 deletions lib/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Tracer = require('./tracer')
const Replicator = require('./replicator')
const { SWAP } = require('./constants')
const releaseWatcher = require('./release-watcher')
const safetyCatch = require('safety-catch')
const noop = Function.prototype

module.exports = class Bundle {
Expand Down Expand Up @@ -59,7 +60,11 @@ module.exports = class Bundle {
} else {
this.replicator = null
}
if (typeof updateNotify === 'function') this.#updates(updateNotify)

// TODO: why is this called here? this.#updates awaits this.ready()
// so we end up running the ready logic before the constructor fully ran
// which crashes because this.initializing is not yet set
if (typeof updateNotify === 'function') this.#updates(updateNotify).catch(safetyCatch)

this.release = null

Expand All @@ -86,12 +91,12 @@ module.exports = class Bundle {
if (this.updatesDiff) {
this.watchingUpdates = watch(this.drive)
for await (const { key, length, fork, diff } of this.watchingUpdates) {
updateNotify({ key, length, fork }, { link: this.link, diff })
await updateNotify({ key, length, fork }, { link: this.link, diff })
}
} else {
this.watchingUpdates = releaseWatcher(this.drive.version || 0, this.drive)
for await (const upd of this.watchingUpdates) {
updateNotify(
await updateNotify(
{ key: this.hexKey, length: upd.length, fork: upd.fork },
{ link: this.link, diff: null }
)
Expand Down
2 changes: 1 addition & 1 deletion lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class Engine extends ReadyResource {

try {
await this.engine.updater.wait(checkout)
this.engine.sidecar.updateNotify(checkout)
await this.engine.sidecar.updateNotify(checkout)
return true
} catch (err) {
this.report({ err })
Expand Down