Skip to content

Commit 13e84fd

Browse files
chore(docs): add missing example for cloud.Counter (#4051)
Co-authored-by: wingbot <[email protected]> Co-authored-by: monada-bot[bot] <[email protected]>
1 parent 6fcfe7d commit 13e84fd

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

Diff for: docs/docs/04-standard-library/01-cloud/counter.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,24 @@ new cloud.Function(counterFunc);
5151

5252
### Using keys to manage multiple counter values
5353

54-
🚧 Not implemented yet (tracking issue: [#1375](https://github.com/winglang/wing/issues/1375))
54+
```js playground
55+
bring cloud;
56+
57+
let counter = new cloud.Counter(initial: 100);
58+
59+
let counterFunc = inflight () => {
60+
let k1 = "key-1";
61+
let k2 = "key-2";
62+
63+
counter.dec(1, k1); // decrement k1 by 1
64+
counter.inc(11, k2); // increment k2 by 11
65+
66+
assert(counter.peek(k1) == 99); // check the current value of k1
67+
assert(counter.peek(k2) == 111); // check the current value of k2
68+
};
69+
70+
new cloud.Function(counterFunc);
71+
```
5572

5673
## Target-specific details
5774

Diff for: libs/wingsdk/src/cloud/counter.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,24 @@ new cloud.Function(counterFunc);
5151

5252
### Using keys to manage multiple counter values
5353

54-
🚧 Not implemented yet (tracking issue: [#1375](https://github.com/winglang/wing/issues/1375))
54+
```js playground
55+
bring cloud;
56+
57+
let counter = new cloud.Counter(initial: 100);
58+
59+
let counterFunc = inflight () => {
60+
let k1 = "key-1";
61+
let k2 = "key-2";
62+
63+
counter.dec(1, k1); // decrement k1 by 1
64+
counter.inc(11, k2); // increment k2 by 11
65+
66+
assert(counter.peek(k1) == 99); // check the current value of k1
67+
assert(counter.peek(k2) == 111); // check the current value of k2
68+
};
69+
70+
new cloud.Function(counterFunc);
71+
```
5572

5673
## Target-specific details
5774

0 commit comments

Comments
 (0)