Skip to content

Commit

Permalink
WIP: fix retry.html and added retry to readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Rodrigues committed Nov 1, 2019
1 parent 0f8b121 commit 58a6a89
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions examples/retry.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
<option value="backoff">Exponential backoff</option>
</select>
</div>
<div>
<div v-if="mode === 'delay'">
<label for="delay">Delay</label>
<input type="number" name="delay" v-model.number="delay" />
</div>
<p v-if="loading">
loading...
</p>
<p v-if="isRetrying">
<p v-else-if="isRetrying">
retrying in {{ Math.floor(nextRetry - dateNow) }}ms
<span>Current: {{ retryCount }} retries</span>
</p>
<div v-else>
<p>Status: {{ status }}</p>
{{ json }}
<span>{{ json }}</span>
</div>
</div>

Expand Down Expand Up @@ -75,7 +75,7 @@
});

watch(id, id => {
useRetry(() => {
exec(() => {
if (throwError.value) {
throw new Error("blocked");
}
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Currently only works with [composition-api](https://github.com/vuejs/composition
| [useFetch](src/web/fetch.ts) | handles the fetch request | [fetch.html](examples/fetch.html) | |
| [useAxios](src/web/axios.ts) | handles the axios requests | [axios.html](examples/axios.html) | |
| [useCancellablePromise](src/web/cancellablePromise.ts) | allow to cancel promise. **NOTE** javascript doesn't support cancel of promises natively, when you cancel it will only prevent the `result` to be modified | | |
| [useRetry](src/promise/retry.ts) | handles retry login on failure | [retry.html](examples/retry.html) | |



## Types
Expand Down
7 changes: 6 additions & 1 deletion src/promise/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ const defaultStrategy: RetryStrategy = async (
let result: any | null = null;
try {
++i;
result = factory(...args);
if (args) {
result = factory(...args);
} else {
result = factory();
}

if (isPromise(result)) {
result = await result;
}
Expand Down

0 comments on commit 58a6a89

Please sign in to comment.