Skip to content

Commit

Permalink
Implement drain root using script object.
Browse files Browse the repository at this point in the history
See #453.
  • Loading branch information
flatheadmill committed Feb 5, 2015
1 parent 14484e6 commit f3a3087
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions strata.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ prototype(Sheaf, 'splitBranch', cadence(function (async, address, key) {

prototype(Sheaf, 'drainRootAndUnlock', cadence(function (async) {
var locker = this.createLocker(),
script = new Script(this),
children = [], locks = [],
root, pages, records, remainder

Expand Down Expand Up @@ -1073,20 +1074,12 @@ prototype(Sheaf, 'drainRootAndUnlock', cadence(function (async) {
lift.reverse()

this.splice(root, 0, 0, lift)
}, function () {
async.forEach(function (page) {
this.writeBranch(page, this.filename2(page, '.replace'), async())
})(children)
}, function () {
this.writeBranch(root, this.filename2(root, '.pending'), async())
}, function () {
this._rename(root, 0, '.pending', '.commit', async())
}, function () {
async.forEach(function (page) {
this.replace(page, '.replace', async())
})(children)
}, function () {
this.replace(root, '.commit', async())

children.forEach(function (page) {
script.writeBranch(page)
})
script.writeBranch(root)
script.commit(async())
}, function () {
return [ root ]
})
Expand Down

0 comments on commit f3a3087

Please sign in to comment.