Store
Store provides possibility to store Shards bound to keys
Also store replicates shards/keys to the peers in same stack namespace
Setting value
By providing shard:
const shard = await Shard.new<{ hello: string }>(stack, ShardKind.Object, {
hello: 'world',
});
await stack.store.set('hello', shard);
Getting value
const shard = await stack.store.get<{ hello: string }>('hello');
console.log(shard.data); // {"hello": "world"}
Watching for a new value
const shard = await stack.store.get<{ hello: string }>('hello');
shard.put({ hello: 'dstack' });
shard.on('update', (shard) => {
console.log(shard.data); // {"hello": "dstack"}
});
See Shard to get more possibilities