|
1 | 1 | ## Functions
|
2 | 2 |
|
3 | 3 | <dl>
|
4 |
| -<dt><a href="#queueAndAttemptRequest">queueAndAttemptRequest(request)</a> ⇒ <code>Promise</code></dt> |
5 |
| -<dd><p>Stores a request in the queue and then attempts to send it to the server</p> |
| 4 | +<dt><a href="#queueAndAttemptRequest">queueAndAttemptRequest(request)</a> ⇒ <code>Promise.<Response></code></dt> |
| 5 | +<dd><p>Stores a request in the queue and then attempts to send it to the server. |
| 6 | +If there are existing requests in the queue, those will be attempted first to ensure they are sent in the intended order. |
| 7 | +Succesful requests are removed from the queue. The first unsuccessful request blocks subsequent requests. |
| 8 | +Existing PUT and DELETE requests in the queue for the same URL will be dropped if the method is PUT or DELETE.</p> |
6 | 9 | </dd>
|
7 |
| -<dt><a href="#queueRequest">queueRequest(request)</a> ⇒ <code>Promise.<number></code></dt> |
8 |
| -<dd><p>Stores a request object in indexDB</p> |
| 10 | +<dt><a href="#getOutstandingRequests">getOutstandingRequests()</a> ⇒ <code>Promise.<Array.<Request>></code></dt> |
| 11 | +<dd><p>Fetches all the outstanding requests from the queue</p> |
9 | 12 | </dd>
|
10 |
| -<dt><a href="#attemptRequest">attemptRequest(requestid, request)</a> ⇒ <code>Promise.<Response></code></dt> |
11 |
| -<dd><p>Attempts to fetch a request from the queue. If successful, the request is removed from the queue.</p> |
12 |
| -</dd> |
13 |
| -<dt><a href="#removeFromQueue">removeFromQueue(requestid)</a> ⇒ <code>Promise</code></dt> |
14 |
| -<dd><p>Removes a request from the queue</p> |
15 |
| -</dd> |
16 |
| -<dt><a href="#getOutstandingRequestsAndIds">getOutstandingRequestsAndIds()</a> ⇒ <code>Array.<{id: number, request: Request}></code></dt> |
17 |
| -<dd><p>Fetches all the outstanding requests, along with their IDs from indexDB |
18 |
| -NB: getOutstandRequests is a simplified public wrapper for this function, which doesn't expose the internal requestids</p> |
19 |
| -</dd> |
20 |
| -<dt><a href="#getOutstandingRequests">getOutstandingRequests()</a> ⇒ <code>Array.<Request></code></dt> |
21 |
| -<dd><p>Fetches all the outstanding requests from indexDB</p> |
22 |
| -</dd> |
23 |
| -<dt><a href="#syncRequests">syncRequests()</a></dt> |
24 |
| -<dd><p>Starts off an asynchronous function to sync up any outstanding requests with the server |
25 |
| -Ensures there's only one running at a time to avoid race conditions</p> |
26 |
| -</dd> |
27 |
| -<dt><a href="#attemptOutstandingRequests">attemptOutstandingRequests()</a> ⇒ <code>Promise</code></dt> |
28 |
| -<dd><p>Attempts to fetch an outstanding requests, and if successful remove them from the queue. |
29 |
| -Stops after the first failure and doesn't attempt any subsequent requests in the queue. |
30 |
| -NB: Calling this function whilst a previous invocation hasn't completed yet, may cause a race condition. Use the <code>syncRequests</code> function to avoid this.</p> |
31 |
| -</dd> |
32 |
| -<dt><a href="#pruneQueueByUrl">pruneQueueByUrl(url)</a> ⇒ <code>Promise</code></dt> |
33 |
| -<dd><p>Removes all PUT or DELETE requests to the given URL from the queue |
34 |
| -This is because a subsequest request will make these unneeded</p> |
| 13 | +<dt><a href="#syncRequests">syncRequests()</a> ⇒ <code>Promise</code></dt> |
| 14 | +<dd><p>Asynchronously attempts to send queued requests to the server in order. |
| 15 | +Succesful requests are removed from the queue. The first unsuccessful request blocks subsequent requests. |
| 16 | +To avoid any race conditions, only one attempt to sync the queue will happen at a time. |
| 17 | +If called when an existing attempt is being made, another attempt will be made after the current one completes.</p> |
35 | 18 | </dd>
|
36 | 19 | </dl>
|
37 | 20 |
|
38 | 21 | <a name="queueAndAttemptRequest"></a>
|
39 | 22 |
|
40 |
| -## queueAndAttemptRequest(request) ⇒ <code>Promise</code> |
41 |
| -Stores a request in the queue and then attempts to send it to the server |
42 |
| - |
43 |
| -**Kind**: global function |
44 |
| - |
45 |
| -| Param | Type | Description | |
46 |
| -| --- | --- | --- | |
47 |
| -| request | <code>Request</code> | A Request object from the Fetch API, which isn't unusable | |
48 |
| - |
49 |
| -<a name="queueRequest"></a> |
50 |
| - |
51 |
| -## queueRequest(request) ⇒ <code>Promise.<number></code> |
52 |
| -Stores a request object in indexDB |
53 |
| - |
54 |
| -**Kind**: global function |
55 |
| -**Returns**: <code>Promise.<number></code> - A promise which resolves with a unique requestid when succesfully stored (or rejects on failure) |
56 |
| - |
57 |
| -| Param | Type | Description | |
58 |
| -| --- | --- | --- | |
59 |
| -| request | <code>Request</code> | A Request object from the Fetch API | |
60 |
| - |
61 |
| -<a name="attemptRequest"></a> |
62 |
| - |
63 |
| -## attemptRequest(requestid, request) ⇒ <code>Promise.<Response></code> |
64 |
| -Attempts to fetch a request from the queue. If successful, the request is removed from the queue. |
| 23 | +## queueAndAttemptRequest(request) ⇒ <code>Promise.<Response></code> |
| 24 | +Stores a request in the queue and then attempts to send it to the server. |
| 25 | +If there are existing requests in the queue, those will be attempted first to ensure they are sent in the intended order. |
| 26 | +Succesful requests are removed from the queue. The first unsuccessful request blocks subsequent requests. |
| 27 | +Existing PUT and DELETE requests in the queue for the same URL will be dropped if the method is PUT or DELETE. |
65 | 28 |
|
66 | 29 | **Kind**: global function
|
67 |
| -**Returns**: <code>Promise.<Response></code> - A promise which resolves with the requests response following removal from the queue (or rejects on failure) |
| 30 | +**Returns**: <code>Promise.<Response></code> - A promise which resolves with a "202 Added to Queue" response once the request has been successfully added to the queue. |
68 | 31 |
|
69 | 32 | | Param | Type | Description |
|
70 | 33 | | --- | --- | --- |
|
71 |
| -| requestid | <code>number</code> | The unique ID for this request stored in indexDB | |
72 |
| -| request | <code>Request</code> | A Request object from the Fetch API | |
| 34 | +| request | <code>Request</code> | A Request object from the Fetch API. Must not be in an "unusable" state. | |
73 | 35 |
|
74 |
| -<a name="removeFromQueue"></a> |
75 |
| - |
76 |
| -## removeFromQueue(requestid) ⇒ <code>Promise</code> |
77 |
| -Removes a request from the queue |
78 |
| - |
79 |
| -**Kind**: global function |
80 |
| -**Returns**: <code>Promise</code> - A promise which resolves when succesfully removed (or rejects on failure) |
81 |
| - |
82 |
| -| Param | Type | Description | |
83 |
| -| --- | --- | --- | |
84 |
| -| requestid | <code>number</code> | The unique ID for the request to remove from indexDB+ | |
85 |
| - |
86 |
| -<a name="getOutstandingRequestsAndIds"></a> |
87 |
| - |
88 |
| -## getOutstandingRequestsAndIds() ⇒ <code>Array.<{id: number, request: Request}></code> |
89 |
| -Fetches all the outstanding requests, along with their IDs from indexDB |
90 |
| -NB: getOutstandRequests is a simplified public wrapper for this function, which doesn't expose the internal requestids |
91 |
| - |
92 |
| -**Kind**: global function |
93 |
| -**Returns**: <code>Array.<{id: number, request: Request}></code> - An array containing requests and their associated requestids |
94 | 36 | <a name="getOutstandingRequests"></a>
|
95 | 37 |
|
96 |
| -## getOutstandingRequests() ⇒ <code>Array.<Request></code> |
97 |
| -Fetches all the outstanding requests from indexDB |
| 38 | +## getOutstandingRequests() ⇒ <code>Promise.<Array.<Request>></code> |
| 39 | +Fetches all the outstanding requests from the queue |
98 | 40 |
|
99 | 41 | **Kind**: global function
|
100 |
| -**Returns**: <code>Array.<Request></code> - An array containing Fetch API Request objects |
| 42 | +**Returns**: <code>Promise.<Array.<Request>></code> - An array of outstanding requests in the order they are to be sent to the server |
101 | 43 | <a name="syncRequests"></a>
|
102 | 44 |
|
103 |
| -## syncRequests() |
104 |
| -Starts off an asynchronous function to sync up any outstanding requests with the server |
105 |
| -Ensures there's only one running at a time to avoid race conditions |
106 |
| - |
107 |
| -**Kind**: global function |
108 |
| -<a name="attemptOutstandingRequests"></a> |
109 |
| - |
110 |
| -## attemptOutstandingRequests() ⇒ <code>Promise</code> |
111 |
| -Attempts to fetch an outstanding requests, and if successful remove them from the queue. |
112 |
| -Stops after the first failure and doesn't attempt any subsequent requests in the queue. |
113 |
| -NB: Calling this function whilst a previous invocation hasn't completed yet, may cause a race condition. Use the `syncRequests` function to avoid this. |
| 45 | +## syncRequests() ⇒ <code>Promise</code> |
| 46 | +Asynchronously attempts to send queued requests to the server in order. |
| 47 | +Succesful requests are removed from the queue. The first unsuccessful request blocks subsequent requests. |
| 48 | +To avoid any race conditions, only one attempt to sync the queue will happen at a time. |
| 49 | +If called when an existing attempt is being made, another attempt will be made after the current one completes. |
114 | 50 |
|
115 | 51 | **Kind**: global function
|
116 | 52 | **Returns**: <code>Promise</code> - A promise which resolves when all requests have been succesfully removed from the queue, or rejects after encountering the first failure
|
117 |
| -<a name="pruneQueueByUrl"></a> |
118 |
| - |
119 |
| -## pruneQueueByUrl(url) ⇒ <code>Promise</code> |
120 |
| -Removes all PUT or DELETE requests to the given URL from the queue |
121 |
| -This is because a subsequest request will make these unneeded |
122 |
| - |
123 |
| -**Kind**: global function |
124 |
| -**Returns**: <code>Promise</code> - A promise which resolves when the pruning has completed |
125 |
| - |
126 |
| -| Param | Type | Description | |
127 |
| -| --- | --- | --- | |
128 |
| -| url | <code>string</code> | The URL of requests to prune from the queue | |
129 |
| - |
0 commit comments