Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
Fix for the order dats are loaded (#455)
Browse files Browse the repository at this point in the history
* Making sure that onupdate is not called before the return happened in order to prevent zalgo from hauting us at night.

* Fixing problems with not running update in zalgo style.

* Making sure that the dats are closed before trying to join the network.
  • Loading branch information
martinheidegger authored and juliangruber committed Jan 29, 2018
1 parent 2aaf542 commit cab9e5a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/dat-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ function createManager ({ multidat, dbPaused }, onupdate) {
var dats = multidat.list()
var speed = { up: 0, down: 0 }
dats.forEach(initDat)
onupdate(null, dats, speed)
setImmediate(function () {
onupdate(null, dats, speed)
})

return {
create: create,
Expand Down Expand Up @@ -144,6 +146,7 @@ function createManager ({ multidat, dbPaused }, onupdate) {
const key = encoding.toStr(dat.key)
dbPaused.read((err, paused) => {
if (err) throw err
if (dat._closed) return
if (!paused[key]) {
dat.joinNetwork()
dat.network.on('connection', function (connection) {
Expand All @@ -158,6 +161,7 @@ function createManager ({ multidat, dbPaused }, onupdate) {

dat.archive.readFile('/dat.json', function (err, blob) {
if (err && !dat.writable) return
if (dat._closed) return
if (err) {
var json = datJson(dat)
json.write(next)
Expand Down
4 changes: 2 additions & 2 deletions models/dats.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ function datsModel (state, bus) {
state.dats.speed = speed
state.dats.ready = true
bus.emit('render')
bus.emit('dats:loaded')
done()
})
bus.emit('dats:loaded')
done()
}
]

Expand Down
2 changes: 1 addition & 1 deletion models/intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function introModel (state, bus) {

// FIXME: wait for DOMContentLoaded
// requires some sort of global load event first
bus.on('dats:loaded', function () {
bus.once('dats:loaded', function () {
if (state.dats.values.length) return
state.intro.show = true
bus.emit('render')
Expand Down

0 comments on commit cab9e5a

Please sign in to comment.