-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
256 additions
and
25 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/swingset-runner/demo/resolveCircular/bootstrap.js
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,26 @@ | ||
import harden from '@agoric/harden'; | ||
|
||
console.log(`=> loading bootstrap.js`); | ||
|
||
function build(E, log) { | ||
return { | ||
bootstrap(argv, vats) { | ||
const pa = E(vats.bob).genPromise1(); | ||
const pb = E(vats.bob).genPromise2(); | ||
const pc = E(vats.bob).usePromises([pa], [pb]); | ||
}, | ||
}; | ||
} | ||
|
||
export default function setup(syscall, state, helpers) { | ||
function log(what) { | ||
helpers.log(what); | ||
console.log(what); | ||
} | ||
return helpers.makeLiveSlots( | ||
syscall, | ||
state, | ||
E => harden(build(E, 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(E, log) { | ||
let p1, r1; | ||
let p2, r2; | ||
return { | ||
genPromise1() { | ||
[p1, r1] = makePR(); | ||
return p1; | ||
}, | ||
genPromise2() { | ||
[p2, r2] = makePR(); | ||
return p2; | ||
}, | ||
usePromises(pa, pb) { | ||
r1(pb); | ||
r2(pa); | ||
}, | ||
}; | ||
} | ||
|
||
export default function setup(syscall, state, helpers) { | ||
function log(what) { | ||
helpers.log(what); | ||
console.log(what); | ||
} | ||
return helpers.makeLiveSlots( | ||
syscall, | ||
state, | ||
E => harden(build(E, 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
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
25 changes: 25 additions & 0 deletions
25
packages/swingset-runner/demo/resolveSimpleCicular/bootstrap.js
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,25 @@ | ||
import harden from '@agoric/harden'; | ||
|
||
console.log(`=> loading bootstrap.js`); | ||
|
||
function build(E, log) { | ||
return { | ||
bootstrap(argv, vats) { | ||
const pa = E(vats.bob).genPromise(); | ||
const pb = E(vats.bob).usePromise([pa]); | ||
}, | ||
}; | ||
} | ||
|
||
export default function setup(syscall, state, helpers) { | ||
function log(what) { | ||
helpers.log(what); | ||
console.log(what); | ||
} | ||
return helpers.makeLiveSlots( | ||
syscall, | ||
state, | ||
E => harden(build(E, log)), | ||
helpers.vatID, | ||
); | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/swingset-runner/demo/resolveSimpleCicular/vat-bob.js
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,35 @@ | ||
import harden from '@agoric/harden'; | ||
|
||
function makePR() { | ||
let r; | ||
const p = new Promise((resolve, _reject) => { | ||
r = resolve; | ||
}); | ||
return [p, r]; | ||
} | ||
|
||
function build(E, log) { | ||
let p, r; | ||
return { | ||
genPromise() { | ||
[p, r] = makePR(); | ||
return p; | ||
}, | ||
usePromise(pa) { | ||
r(pa); | ||
}, | ||
}; | ||
} | ||
|
||
export default function setup(syscall, state, helpers) { | ||
function log(what) { | ||
helpers.log(what); | ||
console.log(what); | ||
} | ||
return helpers.makeLiveSlots( | ||
syscall, | ||
state, | ||
E => harden(build(E, log)), | ||
helpers.vatID, | ||
); | ||
} |
49 changes: 49 additions & 0 deletions
49
packages/swingset-runner/demo/resolveWithEmbeddedPromise/bootstrap.js
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,49 @@ | ||
import harden from '@agoric/harden'; | ||
|
||
console.log(`=> loading bootstrap.js`); | ||
|
||
function build(E, log) { | ||
return { | ||
bootstrap(argv, vats) { | ||
console.log('=> Alice: bootstrap() called'); | ||
|
||
const p1 = E(vats.bob).first(); | ||
const p2 = E(vats.bob).second(p1); | ||
const p3 = E(vats.bob).third(); | ||
p1.then( | ||
r => { | ||
log(`=> Alice: Bob.first resolved to '${r}' (should be a promise in an array)`); | ||
r[0].then( | ||
rr => log(`=> Alice: Bob.first result resolved to '${rr}'`), | ||
ee => log(`=> Alice: Bob.first result rejected as '${ee}'`), | ||
); | ||
}, | ||
e => log(`=> Alice: Bob.first rejected as '${e}'`), | ||
); | ||
p2.then( | ||
r => log(`=> Alice: Bob.second resolved to '${r}'`), | ||
e => log(`=> Alice: Bob.second rejected as '${e}'`), | ||
); | ||
p3.then( | ||
r => log(`=> Alice: Bob.third resolved to '${r}'`), | ||
e => log(`=> Alice: Bob.third rejected as '${e}'`), | ||
); | ||
log('=> Alice: bootstrap() done'); | ||
return 'Alice started'; | ||
}, | ||
}; | ||
} | ||
|
||
export default function setup(syscall, state, helpers) { | ||
function log(what) { | ||
helpers.log(what); | ||
console.log(what); | ||
} | ||
log(`=> setup called`); | ||
return helpers.makeLiveSlots( | ||
syscall, | ||
state, | ||
E => harden(build(E, log)), | ||
helpers.vatID, | ||
); | ||
} |
52 changes: 52 additions & 0 deletions
52
packages/swingset-runner/demo/resolveWithEmbeddedPromise/vat-bob.js
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,52 @@ | ||
import harden from '@agoric/harden'; | ||
|
||
function makePR() { | ||
let r; | ||
const p = new Promise((resolve, _reject) => { | ||
r = resolve; | ||
}); | ||
return [p, r]; | ||
} | ||
|
||
function build(_E, log) { | ||
let r1; | ||
let r2; | ||
return { | ||
first() { | ||
log('=> Bob: first begins'); | ||
let p1; | ||
[p1, r1] = makePR(); | ||
return p1; | ||
}, | ||
second(p) { | ||
log('=> Bob: second begins'); | ||
let p2; | ||
[p2, r2] = makePR(); | ||
r1([p2]); | ||
p.then( | ||
r => log(`=> Bob: second(p) resolved to '${r}'`), | ||
e => log(`=> Bob: second(p) rejected as '${e}'`), | ||
); | ||
log('=> Bob: second done'); | ||
return p2; | ||
}, | ||
third(p) { | ||
log('=> Bob: third begins'); | ||
r2(`Bob's resolution to p2`); | ||
return `Bob's answer to third`; | ||
} | ||
}; | ||
} | ||
|
||
export default function setup(syscall, state, helpers) { | ||
function log(what) { | ||
helpers.log(what); | ||
console.log(what); | ||
} | ||
return helpers.makeLiveSlots( | ||
syscall, | ||
state, | ||
E => harden(build(E, log)), | ||
helpers.vatID, | ||
); | ||
} |