|
1 | | -from typing import TypeVar, Tuple, List |
2 | | -from componentize_py_types import Result, Err |
3 | | -from componentize_py_async_support.streams import StreamReader |
4 | | -from componentize_py_async_support.futures import FutureReader |
5 | | -from spin_sdk import http, key_value |
| 1 | +from spin_sdk import http, key_value, util |
6 | 2 | from spin_sdk.http import Request, Response |
7 | 3 | from spin_sdk.key_value import Store |
8 | 4 |
|
9 | 5 | class WasiHttpHandler030Rc20260315(http.Handler): |
10 | 6 | async def handle_request(self, request: Request) -> Response: |
11 | 7 | with await key_value.open_default() as a: |
12 | 8 | await a.set("test", bytes("hello world!", "utf-8")) |
13 | | - print(await get_keys(a)) |
| 9 | + print(await util.collect(await a.get_keys())) |
14 | 10 | print(await a.exists("test")) |
15 | 11 | print(await a.get("test")) |
16 | 12 | await a.delete("test") |
17 | | - print(await get_keys(a)) |
| 13 | + print(await util.collect(await a.get_keys())) |
18 | 14 |
|
19 | 15 | return Response( |
20 | 16 | 200, |
21 | 17 | {"content-type": "text/plain"}, |
22 | 18 | bytes("Hello from Python!", "utf-8") |
23 | 19 | ) |
24 | | - |
25 | | -async def get_keys(store: Store) -> list[str]: |
26 | | - stream, future = await store.get_keys() |
27 | | - with stream, future: |
28 | | - keys = [] |
29 | | - while not stream.writer_dropped: |
30 | | - keys += await stream.read(max_count=100) |
31 | | - return keys |
0 commit comments