Skip to content

Instantly share code, notes, and snippets.

@katelynsills
katelynsills / baytownbucks.js
Created November 2, 2019 02:06
Baytown Bucks
import { makeMint } from '@agoric/ertp/core/mint';
const baytownBucksMint = makeMint('BaytownBucks');
const purse = baytownBucksMint.mint(1000, 'community treasury');
const paymentForAlice = purse.withdraw(10, `alice's community money`);
alice.receivePayment(paymentForAlice);

Keybase proof

I hereby claim:

  • I am katelynsills on github.
  • I am kate_sills (https://keybase.io/kate_sills) on keybase.
  • I have a public key ASAoaGeWMR7V9a8pMqV6lqqbVeca7MWjKZZ2nw_krPUAHAo

To claim this, I am signing this object:

const result = disk~.openDirectory("foo")~.openFile("bar.txt")~.read();
@katelynsills
katelynsills / finance-listener-P.js
Created January 24, 2019 19:41
We use a promise in our finance listener
const financeListener = {
stateChanged(state) {
if (state < 4000) {
Promise.resolve(bankAccount).then(ba => ba.deposit(1000));
}
},
};
@katelynsills
katelynsills / state-holder-update-state-P.js
Last active January 27, 2019 17:07
We can rewrite the updateState method for our stateHolder such that it notifies the listeners asynchronously
updateState(newState) {
state = newState;
listeners.forEach(listener => {
Promise.resolve(listener).then(ev => ev.stateChanged(newState));
});
},
@katelynsills
katelynsills / create-state-holder-P.js
Created January 24, 2019 19:08
A promises version of our stateHolder
function makeStateHolder() {
let state = undefined;
const listeners = [];
return {
addListener(newListener) {
listeners.push(newListener);
},
getState() {
return state;
@katelynsills
katelynsills / listener-pattern-example-P.js
Last active January 24, 2019 19:39
We can solve the interleaving hazard by using promises
/* make listener infrastructure */
function makeStateHolder() {
let state = undefined;
const listeners = [];
return {
addListener(newListener) {
listeners.push(newListener);
},
stateHolder.addListener(financeListener);
stateHolder.addListener(webpageListener);
bankAccount.withdraw(100);
const webpageListener = {
stateChanged(state) {
console.log('DISPLAYED BALANCE', state);
},
};
const financeListener = {
stateChanged(state) {
if (state < 4000) {
bankAccount.deposit(1000);
}
},
};