# Async.AwaitTask that re-evaluates Task

**URL:** <https://forums.fsharp.org/t/async-awaittask-that-re-evaluates-task/404>\
**Category:** General\
**Created:** [August 14, 2018, 8:22pm UTC](https://forums.fsharp.org/t/async-awaittask-that-re-evaluates-task/404 "2018-08-14T20:22:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nelkins](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/nelkins/32/173_2.png) [@Nelkins](https://forums.fsharp.org/u/Nelkins)\
**Post date:** [August 14, 2018, 8:22pm UTC](https://forums.fsharp.org/t/async-awaittask-that-re-evaluates-task/404/1 "2018-08-14T20:22:15Z")

</div>

I’m calling `GetAsync` on an `HttpClient` and then using it with `Async.AwaitTask`. I am then piping that `Async<HttpResponseMessage>` into some retry logic, which should re-evaluate the `Async<HttpResponseMessage>` if it has a non-200 status code. However, it retains its Task-like behavior (using the completed/cached result) instead of making the call again (like I would expect if it were a normal `Async`. Does anybody know of an `AwaitTask` implementation that provides the behavior I’m looking for, where the `Task` will be re-evaluated also?

Thanks!

---

<div class="post-metadata">

**Author:** ![Nelkins](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/nelkins/32/173_2.png) [@Nelkins](https://forums.fsharp.org/u/Nelkins)\
**Post date:** [August 14, 2018, 9:40pm UTC](https://forums.fsharp.org/t/async-awaittask-that-re-evaluates-task/404/2 "2018-08-14T21:40:13Z")

</div>

I ended up solving this by putting the creation of the Task into an Async. Curious to know if there’s another way of doing this though.

---

<div class="post-metadata">

**Author:** ![chethusk](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/chethusk/32/11_2.png) [@chethusk](https://forums.fsharp.org/u/chethusk)\
**Post date:** [August 14, 2018, 11:12pm UTC](https://forums.fsharp.org/t/async-awaittask-that-re-evaluates-task/404/3 "2018-08-14T23:12:48Z")

</div>

It’s going to be very hard, because by definition a `Task` is an one-time action. It caches the result of that single run in the `Result` property, and the Task itself has no idea what caused it to be spawned (ie is it an http-request Task, or a database call, etc). If you want to be able to use a retry-able task, you either need to have some kind of Task-generator (a function of type `unit -> Task<'t>`) that gets passed into your initial Async-creating function, or rewrite the operation in terms of an Async in the first place.
