Skip to content

Commit

Permalink
Have kv-store#open return an optional handle (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottt authored May 23, 2024
1 parent 33dab4a commit f23127e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 3 additions & 7 deletions lib/src/component/kv_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use {
super::fastly::api::{http_types, kv_store, types},
crate::{
body::Body,
error,
object_store::{ObjectKey, ObjectStoreError},
session::{
PeekableTask, PendingKvDeleteTask, PendingKvInsertTask, PendingKvLookupTask, Session,
Expand All @@ -12,15 +11,12 @@ use {

#[async_trait::async_trait]
impl kv_store::Host for Session {
async fn open(&mut self, name: String) -> Result<kv_store::Handle, types::Error> {
async fn open(&mut self, name: String) -> Result<Option<kv_store::Handle>, types::Error> {
if self.object_store.store_exists(&name)? {
let handle = self.obj_store_handle(&name)?;
Ok(handle.into())
Ok(Some(handle.into()))
} else {
Err(
error::Error::ObjectStoreError(ObjectStoreError::UnknownObjectStore(name.clone()))
.into(),
)
Ok(None)
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/wit/deps/fastly/compute.wit
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ interface kv-store {
type pending-insert-handle = u32;
type pending-delete-handle = u32;

open: func(name: string) -> result<handle, error>;
open: func(name: string) -> result<option<handle>, error>;

lookup: func(
store: handle,
Expand Down

0 comments on commit f23127e

Please sign in to comment.