diff --git a/versioned_docs/version-latest/02-concepts/03-compile-targets.md b/versioned_docs/version-latest/02-concepts/03-compile-targets.md index 340702a91..82b5c63c5 100644 --- a/versioned_docs/version-latest/02-concepts/03-compile-targets.md +++ b/versioned_docs/version-latest/02-concepts/03-compile-targets.md @@ -58,39 +58,33 @@ There might be times when you need to write code that is specific to a compiler With the Wing `util` library, you can access environment variables. The `WING_TARGET` environment variable contains the current compiler target, which you can use to conditionally run target-specific code. See the example below: -```js +```js playground bring cloud; bring util; -let bucket = new cloud.Bucket(); -let counter = new cloud.Counter(); +let invocationCounter = new cloud.Counter(); let queue = new cloud.Queue(); queue.setConsumer(inflight (msg: str) => { - let i = counter.inc(); - bucket.put("file-${i}.txt", msg); + invocationCounter.inc(); }); -// only create this verbose logger if our Wing target is sim -if util.env("WING_TARGET") == "sim" { - let verboseLogger = new cloud.Service( - onStart: inflight() => { - // Continuously log the files in the bucket every 10 seconds - while true { - util.sleep(10s); - log("Files in bucket"); - log("=================="); - for f in bucket.list() { - log(f); - } - log("==================="); - } - } - ); -} +new cloud.Function(inflight ()=> { + // push a message to queue + queue.push("m"); + // sleep according to target + if util.env("WING_TARGET") == "sim" { + log("Running on Simulator, sleeping for 1s"); + util.sleep(1s); + } else { + log("Running on the cloud, sleeping for 30s"); + util.sleep(30s); + } + log("Function invoked ${invocationCounter.peek()} times"); +}); ``` -In this example, we're creating a verbose logger service only when the `WING_TARGET` environment variable is set to "sim". The `onStart` function of this service lists the files in the bucket and logs them every 10 seconds. +In this example, we want to sleep briefly for the Simulator target and for 30 seconds for cloud targets, this is achieved using the `WING_TARGET` environment variable. ## Compiler plugins diff --git a/versioned_docs/version-latest/07-examples/01-variable-declaration.md b/versioned_docs/version-latest/07-examples/01-variable-declaration.md index 1380d4088..d18b709d6 100644 --- a/versioned_docs/version-latest/07-examples/01-variable-declaration.md +++ b/versioned_docs/version-latest/07-examples/01-variable-declaration.md @@ -8,7 +8,7 @@ keywords: [Wing example] ```ts let x = 12; -x = 77; // ERROR: x is non reassignable +x = 77; // error: Variable is not reassignable let var y = "hello"; y = "world"; // OK (y is reassignable) @@ -31,7 +31,7 @@ x1 = nil; // ERROR: Expected type to be "str", but got "nil" instead x3 = nil; // OK (x3 is optional) ``` ### Scopes -```ts playground +```ts let s = "parent"; log(s); // prints parent if true { diff --git a/versioned_docs/version-latest/07-examples/02-primitives.md b/versioned_docs/version-latest/07-examples/02-primitives.md index 3e819d3e0..dc0d0cb47 100644 --- a/versioned_docs/version-latest/07-examples/02-primitives.md +++ b/versioned_docs/version-latest/07-examples/02-primitives.md @@ -7,7 +7,7 @@ keywords: [Wing example] ## Str ### Concat and Interpolate -```ts playground +```ts let s1 = "Hello Wing String"; log(s1); // prints Hello Wing String let s2 = "Interpolate: ${s1}"; // string interpolation @@ -17,7 +17,7 @@ log(s3); // prints Concat: Hello Wing String ``` ### Str methods -```ts playground +```ts let s = "Hello to a new Wing world"; // lets start with split @@ -45,7 +45,7 @@ for w in s.split(" ") { ## Num -```ts playground +```ts let n1 = 10; log("${n1}"); // 10 @@ -68,7 +68,7 @@ log("${n6}"); // The meaning of the universe ## Bool -```ts playground +```ts let b1 = true; let b2 = false; diff --git a/versioned_docs/version-latest/07-examples/03-functions.md b/versioned_docs/version-latest/07-examples/03-functions.md index 67f40064f..554763dac 100644 --- a/versioned_docs/version-latest/07-examples/03-functions.md +++ b/versioned_docs/version-latest/07-examples/03-functions.md @@ -26,7 +26,7 @@ let handler = inflight (message: str): void => { // code }; // inflight modifier is not required when function is declared in inflight context - let dup = (s: str, count: num): str => { + let sup = (s: str, count: num): str => { // code }; };