@@ -137,6 +137,28 @@ impl Server {
137137 }
138138}
139139
140+ impl bindings:: exports:: wasi:: keyvalue:: store:: Handler < Option < HeaderMap > > for Server {
141+ // NOTE: Resource handle returned is just the `identifier` itself
142+ #[ instrument( level = "trace" , skip( _cx) , ret) ]
143+ async fn open (
144+ & self ,
145+ _cx : Option < HeaderMap > ,
146+ identifier : String ,
147+ ) -> anyhow:: Result < Result < ResourceOwn < store:: Bucket > > > {
148+ let identifier = Bytes :: from ( identifier) ;
149+ {
150+ // first, optimistically try read-only lock
151+ let store = self . 0 . read ( ) . await ;
152+ if store. contains_key ( & identifier) {
153+ return Ok ( Ok ( ResourceOwn :: from ( identifier) ) ) ;
154+ }
155+ }
156+ let mut store = self . 0 . write ( ) . await ;
157+ store. entry ( identifier. clone ( ) ) . or_default ( ) ;
158+ Ok ( Ok ( ResourceOwn :: from ( identifier) ) )
159+ }
160+ }
161+
140162impl bindings:: exports:: wasi:: keyvalue:: store:: HandlerBucket < Option < HeaderMap > > for Server {
141163 #[ instrument( level = "trace" , skip( _cx) , ret) ]
142164 async fn get (
@@ -209,25 +231,3 @@ impl bindings::exports::wasi::keyvalue::store::HandlerBucket<Option<HeaderMap>>
209231 Ok ( Ok ( KeyResponse { keys, cursor : None } ) )
210232 }
211233}
212-
213- impl bindings:: exports:: wasi:: keyvalue:: store:: Handler < Option < HeaderMap > > for Server {
214- // NOTE: Resource handle returned is just the `identifier` itself
215- #[ instrument( level = "trace" , skip( _cx) , ret) ]
216- async fn open (
217- & self ,
218- _cx : Option < HeaderMap > ,
219- identifier : String ,
220- ) -> anyhow:: Result < Result < ResourceOwn < store:: Bucket > > > {
221- let identifier = Bytes :: from ( identifier) ;
222- {
223- // first, optimistically try read-only lock
224- let store = self . 0 . read ( ) . await ;
225- if store. contains_key ( & identifier) {
226- return Ok ( Ok ( ResourceOwn :: from ( identifier) ) ) ;
227- }
228- }
229- let mut store = self . 0 . write ( ) . await ;
230- store. entry ( identifier. clone ( ) ) . or_default ( ) ;
231- Ok ( Ok ( ResourceOwn :: from ( identifier) ) )
232- }
233- }
0 commit comments