Skip to content

Commit

Permalink
Merge pull request #28 from hasanaburayyan/hasan/fix-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
skorfmann authored Nov 13, 2023
2 parents 7224358 + 1a085c1 commit 5b50da1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
24 changes: 12 additions & 12 deletions examples/stock-poller/main.w
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ let stockUpdatesPoller = stockUpdatesFetchSchedule.onTick(inflight () => {
log("Status: ${stockUpdates.status}");
log("Body: ${stockUpdates.body}");

if let stockUpdatesBody = stockUpdates.body {
log("Received this stock updates: ${stockUpdatesBody}");
let stockUpdatesBody = stockUpdates.body;

log("Received this stock updates: ${stockUpdatesBody}");

let stockUpdatesBodyJson = Json.parse(stockUpdatesBody);
let latestStockPriceStr = stockUpdatesBodyJson.get("values").getAt(0).get("close").asStr();
let latestStockPrice = num.fromStr(latestStockPriceStr);
let stockUpdatesBodyJson = Json.parse(stockUpdatesBody);
let latestStockPriceStr = stockUpdatesBodyJson.get("values").getAt(0).get("close").asStr();
let latestStockPrice = num.fromStr(latestStockPriceStr);

let previousStockPrice = recentStockPriceCache.peek(tickerSymbol);
log("Stock price for ${tickerSymbol} changed from ${previousStockPrice} to ${latestStockPrice} with a difference of: ${latestStockPrice - previousStockPrice}");
let previousStockPrice = recentStockPriceCache.peek(tickerSymbol);
log("Stock price for ${tickerSymbol} changed from ${previousStockPrice} to ${latestStockPrice} with a difference of: ${latestStockPrice - previousStockPrice}");

recentStockPriceCache.set(latestStockPrice, tickerSymbol);
stockUpdatesQueue.push(stockUpdatesBody);
} else {
throw("Failed to parse stockUpdates body");
}
recentStockPriceCache.set(latestStockPrice, tickerSymbol);
stockUpdatesQueue.push(stockUpdatesBody);


});
6 changes: 2 additions & 4 deletions examples/todo-app/main.w
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,8 @@ class TaskService {
// the system will fetch a random task from the internet
if description == "random" {
let response = http.get("https://www.boredapi.com/api/activity");
if let responseBody = response.body {
let body = Json.parse(responseBody);
description = str.fromJson(body.get("activity"));
}
let body = Json.parse(response.body);
description = str.fromJson(body.get("activity"));
}
let id = this.taskStorage.add(description);
return {
Expand Down

0 comments on commit 5b50da1

Please sign in to comment.