You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if you need to perform error handling within the useTask yielded function, define it on the signal argument first. For example if you were logging all calls to the server.
A bit more info would be great around - what happens to the try/catch block if cancel or cancelAll has been called vs the server returning an error. using the example above
constcomponentLog=log.create("MyComponent")consttask=useTask(function*(signal,){signal.pr.then(()=>componentLog.info('successfully posted'),err=>{if(err==='cancel'){componentLog.warn('request cancelled by user')}else{componentLog.error('failed post',err)}returnPromise.reject(err)})
Thanks again
The text was updated successfully, but these errors were encountered:
ReturnType<typeof useTask> will effectively give you something like Task<any, any>. You can import the Task type directly. Due to the plugin being distributed both for Vue 2 and Vue 3 it can be on two different places right now.
I haven't passed a task via v-model so far. I think it's better to pass explicitly via some named prop.
Regarding the signal.pr.then and signal.pr.catch - that is useful especially if you need to react to task cancellation from within the task itself. From my experience its useful for some kind of generic task utils that can be reused on different places. More clear way seems to me to actually handle this outside:
constsave=async()=>{try{awaitsomeTask.perform();}catch(e){if(e==='cancel'){// usually theres no need to react to cancel}else{// rethrow, fill some ref...}}};
But in general if what needs to happen after the task is performed is only some rerendering (no side-effects such as flash message display, redirects and so on) then I'd just rely on the derived state such as task.last.errortask.last.isCancelled right in the template.
Hope this helps and thanks for the input.
I'll try to incorporate this in the docs later in some way too.
First thank you and well done for making such for a great library
The docs are great, but a few small thoughts on improvements:
Using with typescript
If you are passing a Task down as a property to a child component, you can use the typing
Error handling
if you need to perform error handling within the useTask yielded function, define it on the signal argument first. For example if you were logging all calls to the server.
Cancelation
A bit more info would be great around - what happens to the try/catch block if cancel or cancelAll has been called vs the server returning an error. using the example above
Thanks again
The text was updated successfully, but these errors were encountered: