WebAssembly / wasi-keyvalue

27 stars 10 forks source link

Signature of KeyValue::Atomic::Increment #31

Open karthik2804 opened 6 months ago

karthik2804 commented 6 months ago

Currently, the signature of the atomic increment is

increment: func(bucket: bucket, key: key, delta: u64) -> result<u64, error>;

I would like to understand the reasoning behind the delta argument and the return u64 types. This would not support cases where atomic decrement is desired. Would it be better for the types to be i64 to allow for flexibility?

Mossaka commented 6 months ago

That's a good quetsion. Changing the delta and return value type to i64 indeeds give more flexibility and allows the increment operation to also behave as a decrement if the delta is a negative integer.

The reason behind choosing an u64 is that common usage scenarios like counters, timestamps are all positive and this ensures that the operation will not accidentally decreases the value.

Do you have an use case for decrementing?

Do you think adding a decrement function would be sufficient for your use case?