Skip to content

Commit

Permalink
chore(docs): add missing example for cloud.Counter (#4051)
Browse files Browse the repository at this point in the history
Co-authored-by: wingbot <[email protected]>
Co-authored-by: monada-bot[bot] <[email protected]>
  • Loading branch information
3 people authored Sep 11, 2023
1 parent 6fcfe7d commit 13e84fd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
19 changes: 18 additions & 1 deletion docs/docs/04-standard-library/01-cloud/counter.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,24 @@ new cloud.Function(counterFunc);

### Using keys to manage multiple counter values

🚧 Not implemented yet (tracking issue: [#1375](https://github.com/winglang/wing/issues/1375))
```js playground
bring cloud;

let counter = new cloud.Counter(initial: 100);

let counterFunc = inflight () => {
let k1 = "key-1";
let k2 = "key-2";

counter.dec(1, k1); // decrement k1 by 1
counter.inc(11, k2); // increment k2 by 11

assert(counter.peek(k1) == 99); // check the current value of k1
assert(counter.peek(k2) == 111); // check the current value of k2
};

new cloud.Function(counterFunc);
```

## Target-specific details

Expand Down
19 changes: 18 additions & 1 deletion libs/wingsdk/src/cloud/counter.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,24 @@ new cloud.Function(counterFunc);

### Using keys to manage multiple counter values

🚧 Not implemented yet (tracking issue: [#1375](https://github.com/winglang/wing/issues/1375))
```js playground
bring cloud;

let counter = new cloud.Counter(initial: 100);

let counterFunc = inflight () => {
let k1 = "key-1";
let k2 = "key-2";

counter.dec(1, k1); // decrement k1 by 1
counter.inc(11, k2); // increment k2 by 11

assert(counter.peek(k1) == 99); // check the current value of k1
assert(counter.peek(k2) == 111); // check the current value of k2
};

new cloud.Function(counterFunc);
```

## Target-specific details

Expand Down

0 comments on commit 13e84fd

Please sign in to comment.