-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from sor4chi/feat/wrap-with-block-concurrency-w…
…hile feat: wrap constructor callback with block concurrency while
- Loading branch information
Showing
3 changed files
with
21 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"hono-do": minor | ||
--- | ||
|
||
wrap initialize function of durable object with blockConcurrencyWhile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
import { generateHonoObject } from "hono-do"; | ||
|
||
export const Counter = generateHonoObject("/counter", (app, state) => { | ||
export const Counter = generateHonoObject("/counter", async (app, state) => { | ||
const { storage } = state; | ||
let value = (await storage.get<number>("value")) ?? 0; | ||
|
||
app.post("/increment", async (c) => { | ||
const newVal = 1 + ((await storage.get<number>("value")) || 0); | ||
storage.put("value", newVal); | ||
return c.text(newVal.toString()); | ||
app.post("/increment", (c) => { | ||
storage.put("value", value++); | ||
return c.text(value.toString()); | ||
}); | ||
|
||
app.post("/decrement", async (c) => { | ||
const newVal = -1 + ((await storage.get<number>("value")) || 0); | ||
storage.put("value", newVal); | ||
return c.text(newVal.toString()); | ||
app.post("/decrement", (c) => { | ||
storage.put("value", value--); | ||
return c.text(value.toString()); | ||
}); | ||
|
||
app.get("/", async (c) => { | ||
const value = (await storage.get<number>("value")) || 0; | ||
app.get("/", (c) => { | ||
return c.text(value.toString()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters