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
Since `Fetch` relies on `Concurrent` from the `cats-effect` library, we'll need a runtime for executing our effects. We'll be using `IO`from `cats-effect` to run fetches, but you can use any type that has a `Concurrent` instance.
108
+
Since we'll use `IO` from the `cats-effect` library to execute our fetches, we'll need an `IORuntime` for executing our `IO`instances.
109
109
110
-
For executing `IO`, we need a `ContextShift[IO]` used for running `IO` instances and a `Timer[IO]` that is used for scheduling. Let's go ahead and create them. We'll use a `java.util.concurrent.ScheduledThreadPoolExecutor` with a couple of threads to run our fetches.
importcats.effect.unsafe.implicits.global//Gives us an IORuntime in places it is normally not provided
120
112
```
121
113
114
+
Normally, in your applications, this is provided by `IOApp`, and you should not need to import this except in limited scenarios such as test environments that do not have Cats Effect integration.
115
+
For more information, and particularly on why you would usually not want to make one of these yourself, [see this post by Daniel Spiewak](https://github.com/typelevel/cats-effect/discussions/1562#discussioncomment-254838)
116
+
122
117
## Creating and running a fetch
123
118
124
119
Now that we can convert `Int` values to `Fetch[F, String]`, let's try creating a fetch.
Since `Fetch` relies on `Concurrent` from the `cats-effect` library, we'll need a runtime for executing our effects. We'll be using `IO` from `cats-effect` to run fetches, but you can use any type that has a `Concurrent` instance.
110
-
111
-
For executing `IO`, we need a `ContextShift[IO]` used for running `IO` instances and a `Timer[IO]` that is used for scheduling. Let's go ahead and create them. We'll use a `java.util.concurrent.ScheduledThreadPoolExecutor` with a couple of threads to run our fetches.
109
+
Since we'll use `IO` from the `cats-effect` library to execute our fetches, we'll need an `IORuntime` for executing our `IO` instances.
importcats.effect.unsafe.implicits.global//Gives us an IORuntime in places it is normally not provided
121
113
```
122
114
115
+
Normally, in your applications, this is provided by `IOApp`, and you should not need to import this except in limited scenarios such as test environments that do not have Cats Effect integration.
116
+
For more information, and particularly on why you would usually not want to make one of these yourself, [see this post by Daniel Spiewak](https://github.com/typelevel/cats-effect/discussions/1562#discussioncomment-254838)
117
+
123
118
## Creating and running a fetch
124
119
125
120
Now that we can convert `Int` values to `Fetch[F, String]`, let's try creating a fetch.
As you can see above, the cache will now work between calls and can be used to deduplicate requests over a period of time.
284
279
Note that this does not support any kind of automatic cache invalidation, so you will need to keep track of which values you want to re-fetch if you plan on sharing the cache.
285
-
286
-
```scala mdoc:invisible
287
-
executor.shutdownNow()
288
-
```
289
280
---
290
281
291
282
For more in-depth information, take a look at our [documentation](https://47degrees.github.io/fetch/docs.html).
0 commit comments