Skip to content

Commit

Permalink
Merge pull request #1274 from benjumanji/async-no-more
Browse files Browse the repository at this point in the history
Remove dead references to AsyncStream
  • Loading branch information
vkostyukov authored Apr 13, 2022
2 parents ae89739 + 177f621 commit 4e2fb3f
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 47 deletions.
12 changes: 0 additions & 12 deletions core/src/test/scala/io/finch/FinchSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import cats.Eq
import cats.data.NonEmptyList
import cats.effect.{Effect, IO}
import cats.instances.AllInstances
import com.twitter.concurrent.AsyncStream
import com.twitter.finagle.http._
import com.twitter.io.Buf
import com.twitter.util._
Expand Down Expand Up @@ -176,14 +175,6 @@ trait FinchSpec extends AnyFlatSpec with Matchers with Checkers with AllInstance
a <- Arbitrary.arbitrary[A]
} yield Output.Payload(a, st, cs, hs, c)

def genAsyncStreamOutput[A: Arbitrary]: Gen[Output[AsyncStream[A]]] = Gen.oneOf(
genEmptyOutput,
for {
(st, cs, hs, c) <- genOutputMeta
a <- Arbitrary.arbitrary[A]
} yield Output.Payload(AsyncStream.of(a), st, cs, hs, c)
)

def genOutput[A: Arbitrary]: Gen[Output[A]] = Gen.oneOf(
genPayloadOutput[A],
genFailureOutput,
Expand Down Expand Up @@ -375,9 +366,6 @@ trait FinchSpec extends AnyFlatSpec with Matchers with Checkers with AllInstance

implicit def arbitraryOutput[A: Arbitrary]: Arbitrary[Output[A]] = Arbitrary(genOutput[A])

implicit def arbitraryAsyncStreamOutput[A: Arbitrary]: Arbitrary[Output[AsyncStream[A]]] =
Arbitrary(genAsyncStreamOutput[A])

implicit def arbitraryRequestItem: Arbitrary[items.RequestItem] =
Arbitrary(genRequestItem)

Expand Down
8 changes: 0 additions & 8 deletions core/src/test/scala/io/finch/ServerSentEventSpec.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.finch

import cats.Show
import com.twitter.concurrent.AsyncStream
import com.twitter.io.Buf
import io.finch.internal.HttpContent
import org.scalacheck.Gen.Choose
Expand Down Expand Up @@ -51,13 +50,6 @@ class ServerSentEventSpec extends AnyFlatSpec with Matchers with Checkers {
retry <- Choose.chooseLong.choose(-1000, 1000)
} yield sse.copy(retry = Some(retry))

def streamDataOnlyGenerator: Gen[AsyncStream[ServerSentEvent[String]]] = for {
strs <- Gen.nonEmptyListOf(dataOnlySse)
} yield AsyncStream.fromSeq(strs)

implicit def arbitrarySse: Arbitrary[AsyncStream[ServerSentEvent[String]]] =
Arbitrary(streamDataOnlyGenerator)

val encoder = encodeEventStream[String](Show.fromToString)

it should "encode the event when only 'data' is present" in {
Expand Down
23 changes: 1 addition & 22 deletions docs/mdoc/cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,6 @@ val file: Endpoint[IO, Buf] = get("file") {
content given their _dynamic_ nature. Instead, a static HTTP server (i.e., [Nginx][nginx]) would be
the perfect fit.

It's also possible to _stream_ the file content to the client using [`AsyncStream`][as].

```scala mdoc:silent:nest
import io.finch._
import io.finch.catsEffect._
import com.twitter.conversions.StorageUnitOps._
import com.twitter.concurrent.AsyncStream
import com.twitter.finagle.Http
import com.twitter.io.{Buf, BufReader, Reader}

import java.io.File

val reader: Reader[Buf] = Reader.fromFile(new File("/dev/urandom"))

val file: Endpoint[IO, AsyncStream[Buf]] = get("stream-of-file") {
val chunkedReader = BufReader.chunked(reader, chunkSize = 512.kilobytes.inBytes.toInt)
Ok(Reader.toAsyncStream(chunkedReader))
}
```

### Converting `Errors` into JSON

Finch's own errors are often accumulated in the product `Endpoint` and represented as
Expand Down Expand Up @@ -432,7 +412,7 @@ e(Input.get("/foo")).awaitValueUnsafe()
### Server Sent Events

Finch offers support for [Server Sent Events][server-sent-events] through the `finch-sse` sub-project.
Server Sent Events are represented as `AsyncStream`s and streamed over the chunked HTTP transport.
Server Sent Events are represented as `Stream`s and streamed over the chunked HTTP transport.

The `ServerSentEvent` case class carries an arbitrary `data` field and it's possible to encode any
`ServerSentEvent[A]` for which `cats.Show[A]` is defined.
Expand Down Expand Up @@ -531,7 +511,6 @@ call. See finagle-http-auth's README for more usage details.
[loadbalancing]: http://twitter.github.io/finagle/guide/Clients.html#load-balancing
[futures]: http://twitter.github.io/finagle/guide/Futures.html
[bijection]: https://github.com/twitter/bijection
[as]: https://github.com/twitter/util/blob/develop/util-core/src/main/scala/com/twitter/concurrent/AsyncStream.scala
[cors-filter]: https://github.com/twitter/finagle/blob/develop/finagle-http/src/main/scala/com/twitter/finagle/http/filter/Cors.scala
[cors]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
[server-sent-events]: https://en.wikipedia.org/wiki/Server-sent_events
Expand Down
5 changes: 0 additions & 5 deletions docs/mdoc/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,6 @@ bodies in a single step.
- `jsonBody(Option)[A]` - an alias for `body[A, Application.Json]`.
- `textBody(Option)[A]` - an alias for `body[A, Text.Plain]`

Chunked bodies:

- `asyncBody` - chunked/streamed (only matches chunked requests) body represented as an
`AsyncStream[Buf]`.

#### Multipart

Finch supports reading file uploads and attributes from the `multipart/form-data` HTTP bodies with
Expand Down

0 comments on commit 4e2fb3f

Please sign in to comment.