|
1 | 1 | using System; |
| 2 | +using System.Threading; |
2 | 3 | using System.Threading.Tasks; |
3 | 4 |
|
4 | 5 | namespace Blazored.LocalStorage |
5 | 6 | { |
6 | 7 | public interface ILocalStorageService |
7 | 8 | { |
8 | | - /// <summary> |
9 | | - /// Clears all data from local storage. |
| 9 | + /// <summary> |
| 10 | + /// Clears all data from local storage. |
10 | 11 | /// </summary> |
11 | 12 | /// <returns>A <see cref="ValueTask"/> representing the completion of the operation.</returns> |
12 | | - ValueTask ClearAsync(); |
| 13 | + ValueTask ClearAsync(CancellationToken? cancellationToken = null); |
13 | 14 |
|
14 | | - /// <summary> |
15 | | - /// Retrieve the specified data from local storage and deseralise it to the specfied type. |
16 | | - /// </summary> |
17 | | - /// <param name="key">A <see cref="string"/> value specifying the name of the local storage slot to use</param> |
| 15 | + /// <summary> |
| 16 | + /// Retrieve the specified data from local storage and deseralise it to the specfied type. |
| 17 | + /// </summary> |
| 18 | + /// <param name="key">A <see cref="string"/> value specifying the name of the local storage slot to use</param> |
| 19 | + /// <param name="cancellationToken"> |
| 20 | + /// A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts |
| 21 | + /// (<see cref="JSRuntime.DefaultAsyncTimeout"/>) from being applied. |
| 22 | + /// </param> |
18 | 23 | /// <returns>A <see cref="ValueTask"/> representing the completion of the operation.</returns> |
19 | | - ValueTask<T> GetItemAsync<T>(string key); |
| 24 | + ValueTask<T> GetItemAsync<T>(string key, CancellationToken? cancellationToken = null); |
20 | 25 |
|
21 | | - /// <summary> |
22 | | - /// Retrieve the specified data from local storage as a <see cref="string"/>. |
23 | | - /// </summary> |
24 | | - /// <param name="key">A <see cref="string"/> value specifying the name of the storage slot to use</param> |
| 26 | + /// <summary> |
| 27 | + /// Retrieve the specified data from local storage as a <see cref="string"/>. |
| 28 | + /// </summary> |
| 29 | + /// <param name="key">A <see cref="string"/> value specifying the name of the storage slot to use</param> |
| 30 | + /// <param name="cancellationToken"> |
| 31 | + /// A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts |
| 32 | + /// (<see cref="JSRuntime.DefaultAsyncTimeout"/>) from being applied. |
| 33 | + /// </param> |
25 | 34 | /// <returns>A <see cref="ValueTask"/> representing the completion of the operation.</returns> |
26 | | - ValueTask<string> GetItemAsStringAsync(string key); |
| 35 | + ValueTask<string> GetItemAsStringAsync(string key, CancellationToken? cancellationToken = null); |
27 | 36 |
|
28 | | - /// <summary> |
29 | | - /// Return the name of the key at the specified <paramref name="index"/>. |
30 | | - /// </summary> |
31 | | - /// <param name="index"></param> |
| 37 | + /// <summary> |
| 38 | + /// Return the name of the key at the specified <paramref name="index"/>. |
| 39 | + /// </summary> |
| 40 | + /// <param name="index"></param> |
| 41 | + /// <param name="cancellationToken"> |
| 42 | + /// A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts |
| 43 | + /// (<see cref="JSRuntime.DefaultAsyncTimeout"/>) from being applied. |
| 44 | + /// </param> |
32 | 45 | /// <returns>A <see cref="ValueTask"/> representing the completion of the operation.</returns> |
33 | | - ValueTask<string> KeyAsync(int index); |
| 46 | + ValueTask<string> KeyAsync(int index, CancellationToken? cancellationToken = null); |
34 | 47 |
|
35 | 48 | /// <summary> |
36 | 49 | /// Checks if the <paramref name="key"/> exists in local storage, but does not check its value. |
37 | 50 | /// </summary> |
38 | 51 | /// <param name="key">A <see cref="string"/> value specifying the name of the storage slot to use</param> |
| 52 | + /// <param name="cancellationToken"> |
| 53 | + /// A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts |
| 54 | + /// (<see cref="JSRuntime.DefaultAsyncTimeout"/>) from being applied. |
| 55 | + /// </param> |
39 | 56 | /// <returns>A <see cref="ValueTask"/> representing the completion of the operation.</returns> |
40 | | - ValueTask<bool> ContainKeyAsync(string key); |
| 57 | + ValueTask<bool> ContainKeyAsync(string key, CancellationToken? cancellationToken = null); |
41 | 58 |
|
42 | | - /// <summary> |
43 | | - /// The number of items stored in local storage. |
44 | | - /// </summary> |
| 59 | + /// <summary> |
| 60 | + /// The number of items stored in local storage. |
| 61 | + /// </summary> |
45 | 62 | /// <returns>A <see cref="ValueTask"/> representing the completion of the operation.</returns> |
46 | | - ValueTask<int> LengthAsync(); |
| 63 | + ValueTask<int> LengthAsync(CancellationToken? cancellationToken = null); |
47 | 64 |
|
48 | | - /// <summary> |
49 | | - /// Remove the data with the specified <paramref name="key"/>. |
50 | | - /// </summary> |
51 | | - /// <param name="key">A <see cref="string"/> value specifying the name of the storage slot to use</param> |
| 65 | + /// <summary> |
| 66 | + /// Remove the data with the specified <paramref name="key"/>. |
| 67 | + /// </summary> |
| 68 | + /// <param name="key">A <see cref="string"/> value specifying the name of the storage slot to use</param> |
| 69 | + /// <param name="cancellationToken"> |
| 70 | + /// A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts |
| 71 | + /// (<see cref="JSRuntime.DefaultAsyncTimeout"/>) from being applied. |
| 72 | + /// </param> |
52 | 73 | /// <returns>A <see cref="ValueTask"/> representing the completion of the operation.</returns> |
53 | | - ValueTask RemoveItemAsync(string key); |
| 74 | + ValueTask RemoveItemAsync(string key, CancellationToken? cancellationToken = null); |
54 | 75 |
|
55 | | - /// <summary> |
56 | | - /// Sets or updates the <paramref name="data"/> in local storage with the specified <paramref name="key"/>. |
57 | | - /// </summary> |
58 | | - /// <param name="key">A <see cref="string"/> value specifying the name of the storage slot to use</param> |
59 | | - /// <param name="data">The data to be saved</param> |
| 76 | + /// <summary> |
| 77 | + /// Sets or updates the <paramref name="data"/> in local storage with the specified <paramref name="key"/>. |
| 78 | + /// </summary> |
| 79 | + /// <param name="key">A <see cref="string"/> value specifying the name of the storage slot to use</param> |
| 80 | + /// <param name="data">The data to be saved</param> |
| 81 | + /// <param name="cancellationToken"> |
| 82 | + /// A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts |
| 83 | + /// (<see cref="JSRuntime.DefaultAsyncTimeout"/>) from being applied. |
| 84 | + /// </param> |
60 | 85 | /// <returns>A <see cref="ValueTask"/> representing the completion of the operation.</returns> |
61 | | - ValueTask SetItemAsync<T>(string key, T data); |
| 86 | + ValueTask SetItemAsync<T>(string key, T data, CancellationToken? cancellationToken = null); |
62 | 87 |
|
63 | 88 | /// <summary> |
64 | 89 | /// Sets or updates the <paramref name="data"/> in local storage with the specified <paramref name="key"/>. Does not serialize the value before storing. |
65 | 90 | /// </summary> |
66 | 91 | /// <param name="key">A <see cref="string"/> value specifying the name of the storage slot to use</param> |
67 | 92 | /// <param name="data">The string to be saved</param> |
| 93 | + /// <param name="cancellationToken"> |
| 94 | + /// A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts |
| 95 | + /// (<see cref="JSRuntime.DefaultAsyncTimeout"/>) from being applied. |
| 96 | + /// </param> |
68 | 97 | /// <returns></returns> |
69 | | - ValueTask SetItemAsStringAsync(string key, string data); |
70 | | - |
| 98 | + ValueTask SetItemAsStringAsync(string key, string data, CancellationToken? cancellationToken = null); |
| 99 | + |
71 | 100 | event EventHandler<ChangingEventArgs> Changing; |
72 | 101 | event EventHandler<ChangedEventArgs> Changed; |
73 | 102 | } |
|
0 commit comments