From 13e84fd51d384e7cb6cf09ba3cbb53d59e89106d Mon Sep 17 00:00:00 2001 From: Gary Sassano <10464497+garysassano@users.noreply.github.com> Date: Mon, 11 Sep 2023 10:07:13 +0200 Subject: [PATCH] chore(docs): add missing example for `cloud.Counter` (#4051) Co-authored-by: wingbot <109207340+monadabot@users.noreply.github.com> Co-authored-by: monada-bot[bot] --- .../04-standard-library/01-cloud/counter.md | 19 ++++++++++++++++++- libs/wingsdk/src/cloud/counter.md | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/docs/docs/04-standard-library/01-cloud/counter.md b/docs/docs/04-standard-library/01-cloud/counter.md index 1c865fd92fe..353e9447119 100644 --- a/docs/docs/04-standard-library/01-cloud/counter.md +++ b/docs/docs/04-standard-library/01-cloud/counter.md @@ -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 diff --git a/libs/wingsdk/src/cloud/counter.md b/libs/wingsdk/src/cloud/counter.md index 395d254da21..18ca1456251 100644 --- a/libs/wingsdk/src/cloud/counter.md +++ b/libs/wingsdk/src/cloud/counter.md @@ -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