generated from WebAssembly/wasi-proposal-template
-
Notifications
You must be signed in to change notification settings - Fork 15
WIP change to use resources #28
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -16,28 +16,28 @@ interface cache { | |
|
||
// The `get` operation returns the value passed by a previous `set` for the | ||
// same key within the given TTL or none if there is no such value. | ||
get: func(k: key) -> future-get-result; | ||
get: func(k: key) -> borrow<future-get-result>; | ||
|
||
// This block defines a special resource type used by `get` to emulate | ||
// `future<result<option<incoming-value>,error>>`. In the return value | ||
// of the `get` method, the outer `option` returns `none` when the pollable | ||
// is not yet ready and the inner `option` returns `none` when the | ||
// requested key wasn't present. | ||
type future-get-result = u32; | ||
drop-future-get-result: func(f: future-get-result); | ||
future-get-result-get: func(f: future-get-result) -> option<result<option<incoming-value>, error>>; | ||
listen-to-future-get-result: func(f: future-get-result) -> pollable; | ||
resource future-get-result { | ||
get: func() -> option<result<option<borrow<incoming-value>>, error>>; | ||
listen: func() -> pollable; | ||
} | ||
|
||
// The `exists` operation returns whether a value was previously `set` for | ||
// the given key within the TTL. | ||
exists: func(k: key) -> future-exists-result; | ||
exists: func(k: key) -> borrow<future-exists-result>; | ||
|
||
// This block defines a special resource type used by `exists` to emulate | ||
// `future<result<bool,error>>`. | ||
type future-exists-result = u32; | ||
drop-future-exists-result: func(f: future-exists-result); | ||
future-exists-result-get: func(f: future-exists-result) -> option<result<bool, error>>; | ||
listen-to-future-exists-result: func(f: future-exists-result) -> pollable; | ||
resource future-exists-result { | ||
get: func() -> option<result<bool, error>>; | ||
listen: func() -> pollable; | ||
} | ||
|
||
// The `set` operation sets the given value for the given key for the given | ||
// time-to-live (TTL) duration, if supplied, specified in milliseconds. If | ||
|
@@ -46,14 +46,14 @@ interface cache { | |
// value is updated in-place. In the common case of computing and caching a | ||
// value if the given key is not already in the cache, consider using | ||
// `get-or-set` (below) intead of separate `get` and `set` operations. | ||
set: func(k: key, v: outgoing-value, TTL-ms: option<u32>) -> future-result; | ||
set: func(k: key, v: outgoing-value, TTL-ms: option<u32>) -> borrow<future-result>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as above |
||
|
||
// This block defines a special resource type used by `set` and `delete` to | ||
// emulate `future<result<_,error>>`. | ||
type future-result = u32; | ||
drop-future-result: func(f: future-result); | ||
future-result-get: func(f: future-result) -> option<result<_, error>>; | ||
listen-to-future-result: func(f: future-result) -> pollable; | ||
resource future-result { | ||
get: func() -> option<result<_, error>>; | ||
listen: func() -> pollable; | ||
} | ||
|
||
// The `get-or-set` operation asynchronously returns one of two cases | ||
// enumerated by `get-or-set-entry`: in the `occupied` case, the given key | ||
|
@@ -73,10 +73,10 @@ interface cache { | |
|
||
// This block defines a special resource type used by `get-or-set` to | ||
// emulate `future<result<get-or-set-entry,error>>`. | ||
type future-get-or-set-result = u32; | ||
drop-future-get-or-set-result: func(f: future-get-or-set-result); | ||
future-get-or-set-result-get: func(f: future-get-or-set-result) -> option<result<get-or-set-entry, error>>; | ||
listen-to-future-get-or-set-result: func(f: future-get-or-set-result) -> pollable; | ||
resource future-get-or-set-result { | ||
get: func() -> option<result<get-or-set-entry, error>>; | ||
listen: func() -> pollable; | ||
} | ||
|
||
// The following block defines the `vacancy` resource type. (When resource | ||
// types are added, the `u32` type aliases can be replaced by proper | ||
|
@@ -85,14 +85,14 @@ interface cache { | |
// indicate an error that prevents calling `fill`. An implementation MAY | ||
// have a timeout that drops a vacancy that hasn't been filled in order | ||
// to unblock other waiting `get-or-set` callers. | ||
type vacancy = u32; | ||
drop-vacancy: func(v: vacancy); | ||
vacancy-fill: func(v: vacancy, TTL-ms: option<u32>) -> outgoing-value; | ||
resource vacancy { | ||
fill: func(v: outgoing-value, TTL-ms: option<u32>) -> outgoing-value; | ||
} | ||
|
||
// The `delete` operation removes any value with the given key from the | ||
// cache. Like all cache operations, `delete` is weakly ordered and thus | ||
// concurrent `get` calls may still see deleted keys for a period of time. | ||
// Additionally, due to weak ordering, concurrent `set` calls for the same | ||
// key may or may not get deleted. | ||
delete: func(k: key) -> future-result; | ||
delete: func(k: key) -> borrow<future-result>; | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -15,10 +15,9 @@ interface types { | |
/// 7. Azure Cosmos DB calls a collection of key-value pairs a container | ||
/// | ||
/// In this interface, we use the term `bucket` to refer to a collection of key-value | ||
// Soon: switch to `resource bucket { ... }` | ||
type bucket = u32; | ||
drop-bucket: func(bucket: bucket); | ||
open-bucket: func(name: string) -> result<bucket, error>; | ||
resource bucket { | ||
open: static func(name: string) -> result<bucket, error>; | ||
} | ||
|
||
/// A key is a unique identifier for a value in a bucket. The key is used to | ||
/// retrieve the value from the bucket. | ||
|
@@ -32,14 +31,17 @@ interface types { | |
/// A value is the data stored in a key-value pair. The value can be of any type | ||
/// that can be represented in a byte array. It provides a way to write the value | ||
/// to the output-stream defined in the `wasi-io` interface. | ||
// Soon: switch to `resource value { ... }` | ||
type outgoing-value = u32; | ||
resource outgoing-value { | ||
constructor(); | ||
|
||
from-list: static func(list<u8>) -> outgoing-value; | ||
from-stream: static func(input-stream) -> outgoing-value; | ||
|
||
write-body-sync: func(value: outgoing-value-body-sync) -> result<_, error>; | ||
write-body-async: func() -> result<outgoing-value-body-async, error>; | ||
} | ||
type outgoing-value-body-async = output-stream; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More work is needed here to support streams correctly |
||
type outgoing-value-body-sync = list<u8>; | ||
drop-outgoing-value: func(outgoing-value: outgoing-value); | ||
new-outgoing-value: func() -> outgoing-value; | ||
outgoing-value-write-body-async: func(outgoing-value: outgoing-value) -> result<outgoing-value-body-async, error>; | ||
outgoing-value-write-body-sync: func(outgoing-value: outgoing-value, value: outgoing-value-body-sync) -> result<_, error>; | ||
|
||
/// A incoming-value is a wrapper around a value. It provides a way to read the value | ||
/// from the input-stream defined in the `wasi-io` interface. | ||
|
@@ -49,12 +51,11 @@ interface types { | |
/// value as a list of bytes. | ||
/// 2. `incoming-value-consume-async` consumes the value asynchronously and returns the | ||
/// value as an input-stream. | ||
// Soon: switch to `resource incoming-value { ... }` | ||
type incoming-value = u32; | ||
resource incoming-value { | ||
consume-sync: func() -> result<incoming-value-sync-body, error>; | ||
consume-async: func() -> result<incoming-value-async-body, error>; | ||
size: func() -> u64; | ||
} | ||
type incoming-value-async-body = input-stream; | ||
type incoming-value-sync-body = list<u8>; | ||
drop-incoming-value: func(incoming-value: incoming-value); | ||
incoming-value-consume-sync: func(incoming-value: incoming-value) -> result<incoming-value-sync-body, error>; | ||
incoming-value-consume-async: func(incoming-value: incoming-value) -> result<incoming-value-async-body, error>; | ||
size: func(incoming-value: incoming-value) -> u64; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to return an owned
future-get-result
resource here for consuming?