-
Notifications
You must be signed in to change notification settings - Fork 10.4k
[DO] Adding Durable Object base class #18423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
46edf37
06904e0
d713eff
e34e07e
cac7c34
6088c07
5a9944d
d9e7768
fadcb3b
cb2ba3e
1012ba5
26a7a44
0ada43d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| --- | ||
| title: Durable Object Base Class | ||
| pcx_content_type: concept | ||
| sidebar: | ||
| order: 1 | ||
| --- | ||
|
|
||
| import { Render, Tabs, TabItem, GlossaryTooltip, Type, MetaInfo } from "~/components"; | ||
|
|
||
| {/* DEFINITION OF DO BASE CLASS TBC */} | ||
|
|
||
| ## Methods | ||
|
|
||
| ### `webSocketMessage` | ||
|
|
||
| - <code> webSocketMessage(ws <Type text="WebSocket" />, message{" "} <Type text="string | ArrayBuffer" />)</code>: <Type text="void" /> | ||
|
|
||
| - Called by the system when an accepted WebSocket receives a message. | ||
|
|
||
| - This method can be `async`. | ||
|
|
||
| - This method is not called for WebSocket control frames. The system will respond to an incoming [WebSocket protocol ping](https://www.rfc-editor.org/rfc/rfc6455#section-5.5.2) automatically without interrupting hibernation. | ||
|
|
||
| ### `webSocketClose` | ||
Oxyjun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - <code> webSocketClose(ws <Type text="WebSocket" />, code <Type text="number" />,reason <Type text="string" />, wasClean <Type text="boolean" />)</code>: <Type text="void" /> | ||
Oxyjun marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - Called by the system when a WebSocket is closed. `wasClean()` is true if the connection closed cleanly, false otherwise. | ||
|
|
||
| - This method can be `async`. | ||
|
|
||
| ### `webSocketError` | ||
|
|
||
| - <code> webSocketError(ws <Type text="WebSocket" />, error <Type text="any" />)</code> : <Type text="void" /> | ||
|
|
||
| - Called by the system when any non-disconnection related errors occur. | ||
|
|
||
| - This method can be `async`. | ||
|
|
||
| ## Properties | ||
|
|
||
| {/* Properties of DO Base Class TBC */} | ||
Oxyjun marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Related resources | ||
|
|
||
| - Refer to [Use WebSockets](/durable-objects/best-practices/websockets/) for more information on examples of WebSocket methods and best practices. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| title: SQL Storage | ||
| pcx_content_type: concept | ||
| sidebar: | ||
| order: 5 | ||
| order: 6 | ||
|
|
||
| --- | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,10 +2,10 @@ | |
| title: Durable Object State | ||
| pcx_content_type: concept | ||
| sidebar: | ||
| order: 4 | ||
| order: 5 | ||
| --- | ||
|
|
||
| import { Tabs, TabItem, GlossaryTooltip } from "~/components"; | ||
| import { Tabs, TabItem, GlossaryTooltip, Type, MetaInfo } from "~/components"; | ||
|
|
||
| ## Description | ||
|
|
||
|
|
@@ -267,6 +267,22 @@ export class MyDurableObject extends DurableObject { | |
|
|
||
| - None. | ||
|
|
||
| ## Extended methods | ||
Oxyjun marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### `serializeAttachment` | ||
|
|
||
| - <code> serializeAttachment(value <Type text="any" />)</code>: <Type text="void" /> | ||
|
|
||
| - Keeps a copy of `value` in memory (not on disk) to survive hibernation. The value can be any type supported by the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), which is true of most types. | ||
|
||
|
|
||
| - If you modify `value` after calling this method, those changes will not be retained unless you call this method again. The serialized size of `value` is limited to 2,048 bytes, otherwise this method will throw an error. If you need larger values to survive hibernation, use the [Storage API](/durable-objects/api/storage-api/) and pass the corresponding key to this method so it can be retrieved later. | ||
|
|
||
| ### `deserializeAttachment` | ||
|
|
||
| - `deserializeAttachment()`: <Type text='any' /> | ||
|
|
||
| - Retrieves the most recent value passed to `serializeAttachment()`, or `null` if none exists. | ||
|
|
||
| ## Properties | ||
|
|
||
| ### `id` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| pcx_content_type: configuration | ||
| title: WebGPU | ||
| sidebar: | ||
| order: 8 | ||
| order: 9 | ||
| --- | ||
|
|
||
| :::caution | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -375,11 +375,13 @@ A full example can be found in [Build a WebSocket server with WebSocket Hibernat | |
|
|
||
| Prior to `[email protected]` and Miniflare `v3.20231016.0`, WebSockets did not hibernate when using local development environments such as `wrangler dev` or Miniflare. | ||
|
|
||
| If you are using older versions, note that while hibernatable WebSocket events such as [`webSocketMessage()`](/durable-objects/best-practices/websockets/#websocketmessage) will still be delivered, the Durable Object will never be evicted from memory. | ||
| If you are using older versions, note that while hibernatable WebSocket events such as [`webSocketMessage()`](/durable-objects/api/base/#websocketmessage) will still be delivered, the Durable Object will never be evicted from memory. | ||
|
|
||
| ::: | ||
|
|
||
| ## Related resources | ||
|
|
||
| - [Mozilla Developer Network's (MDN) documentation on the WebSocket class](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) | ||
| - [Cloudflare's WebSocket template for building applications on Workers using WebSockets](https://github.com/cloudflare/websocket-template) | ||
| - [Durable Object base class](/durable-objects/api/base/) | ||
| - [Durable Object State interface](/durable-objects/api/state/) | ||
Uh oh!
There was an error while loading. Please reload this page.