-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(experimental): Replace invoke timeout with AbortSignal
- Loading branch information
Showing
3 changed files
with
50 additions
and
10 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,29 @@ | ||
--- | ||
"anywidget": patch | ||
"@anywidget/types": patch | ||
--- | ||
|
||
Experimental: Replace invoke timeout with more flexible `AbortSignal` | ||
|
||
This allows more flexible control over aborting the invoke request, including delegating to third-party libraries that manage cancellation. | ||
|
||
```js | ||
export default { | ||
async render({ model, el }) { | ||
const controller = new AbortController(); | ||
|
||
// Randomly abort the request after 1 second | ||
setTimeout(() => Math.random() < 0.5 && controller.abort(), 1000); | ||
|
||
const signal = controller.signal; | ||
model | ||
.invoke("echo", "Hello, world", { signal }) | ||
.then((result) => { | ||
el.innerHTML = result; | ||
}) | ||
.catch((err) => { | ||
el.innerHTML = `Error: ${err.message}`; | ||
}); | ||
}, | ||
}; | ||
``` |
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
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