https://github.com/filecoin-project/lassie
Lassie is:
| import ( | |
| "context" | |
| "fmt" | |
| "os" | |
| "time" | |
| "github.com/dgraph-io/badger" | |
| ) | |
| const ( |
| // We model the call stack using a linked list of Generators | |
| // Each Generator has a _return field pointing back to its parent | |
| function stepGen(gen, arg) { | |
| const {done, value} = gen.next(arg) | |
| if(done) { | |
| if(gen._return) { | |
| stepGen(gen._return, value) | |
| } |
| // Model to represent an account in the distributed database | |
| // Accounts are mainly a place users can store information like their private keys, in a password protected | |
| // vault, so they can login conveniently from other devices and keep hold of their private keys and record | |
| // what blogs they are authors of. It's also a way for other users to lookup an authors public keys to validate | |
| // their other objects when determining if a new version of some data really belongs to the blog it claims to be | |
| // related to. | |
| const nacl = require('tweetnacl') | |
| const cbor = require('borc') | |
| class HSAccount { |
| /** | |
| * The function you pass to `asyncPoll` should return a promise | |
| * that resolves with object that satisfies this interface. | |
| * | |
| * The `done` property indicates to the async poller whether to | |
| * continue polling or not. | |
| * | |
| * When done is `true` that means you've got what you need | |
| * and the poller will resolve with `data`. | |
| * |
| // spec: https://github.com/tc39/proposal-weakrefs | |
| // the spec contains an [iterable WeakMap implementation](https://github.com/tc39/proposal-weakrefs#iterable-weakmaps) | |
| // NOTE: this WeakSet implementation is incomplete, only does what I needed | |
| // In Firefox Nightly, visit about:config and enable javascript.options.experimental.weakrefs | |
| class IterableWeakSet extends Set { | |
| add(el) { | |
| super.add(new WeakRef(el)) | |
| } | |
| forEach(fn) { |