-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: kernel promise reference counting
- Loading branch information
Showing
15 changed files
with
625 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import harden from '@agoric/harden'; | ||
|
||
console.log(`=> loading bootstrap.js`); | ||
|
||
function build(log) { | ||
function waitFor(who, p) { | ||
p.then( | ||
answer => { | ||
log(`Alice: Bob answers with value ${answer[0]}`); | ||
if (answer[0] < 3) { | ||
who~.gen(); | ||
waitFor(who, answer[1]); | ||
} | ||
}, | ||
err => { | ||
log(`=> Alice: Bob rejected, ${err}`); | ||
} | ||
); | ||
} | ||
|
||
return { | ||
bootstrap(argv, vats) { | ||
const bob = vats.bob; | ||
const p = bob~.init(); | ||
bob~.gen(); | ||
waitFor(bob, p); | ||
}, | ||
}; | ||
} | ||
|
||
export default function setup(syscall, state, helpers) { | ||
function log(what) { | ||
helpers.log(what); | ||
console.log(what); | ||
} | ||
return helpers.makeLiveSlots( | ||
syscall, | ||
state, | ||
() => harden(build(log)), | ||
helpers.vatID, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import harden from '@agoric/harden'; | ||
|
||
function makePR() { | ||
let r; | ||
const p = new Promise((resolve, _reject) => { | ||
r = resolve; | ||
}); | ||
return [p, r]; | ||
} | ||
|
||
function build(log_) { | ||
let r = null; | ||
let value = 0; | ||
return { | ||
init() { | ||
let p; | ||
[p, r] = makePR(); | ||
return p; | ||
}, | ||
gen() { | ||
let [p, newR] = makePR(); | ||
let answer = [value, p]; | ||
value += 1; | ||
r(answer); | ||
r = newR; | ||
}, | ||
}; | ||
} | ||
|
||
export default function setup(syscall, state, helpers) { | ||
function log(what) { | ||
helpers.log(what); | ||
console.log(what); | ||
} | ||
return helpers.makeLiveSlots( | ||
syscall, | ||
state, | ||
() => harden(build(log)), | ||
helpers.vatID, | ||
); | ||
} |
Oops, something went wrong.