Skip to content

Commit

Permalink
Use zio's service alias in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Aug 20, 2020
1 parent 31f54d5 commit cbb0223
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ package object zio {
/**
* ZIO-environment service definition, which is an SttpBackend.
*/
type SttpClient = Has[SttpBackend[Task, Stream[Throwable, Byte], WebSocketHandler]]
type SttpClient = Has[SttpClient.Service]

object SttpClient {

type Service = SttpBackend[Task, Stream[Throwable, Byte], WebSocketHandler]

/**
* Sends the request. Only requests for which the method & URI are specified can be sent.
*
Expand All @@ -27,7 +29,7 @@ package object zio {
* Known exceptions are converted to one of [[SttpClientException]]. Other exceptions are kept unchanged.
*/
def send[T](request: Request[T, Stream[Throwable, Byte]]): ZIO[SttpClient, Throwable, Response[T]] =
ZIO.accessM(env => env.get[SttpBackend[Task, Stream[Throwable, Byte], WebSocketHandler]].send(request))
ZIO.accessM(env => env.get[Service].send(request))

/**
* Opens a websocket. Only requests for which the method & URI are specified can be sent.
Expand All @@ -44,10 +46,6 @@ package object zio {
def openWebsocket[T, WS_RESULT](
request: Request[T, Nothing]
): ZIO[SttpClient, Throwable, WebSocketResponse[WebSocket[Task]]] =
ZioWebSocketHandler().flatMap(handler =>
ZIO.accessM(env =>
env.get[SttpBackend[Task, Stream[Throwable, Byte], WebSocketHandler]].openWebsocket(request, handler)
)
)
ZioWebSocketHandler().flatMap(handler => ZIO.accessM(env => env.get[Service].openWebsocket(request, handler)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package object zio {
type SttpClient = Has[SttpClient.Service]

object SttpClient {

type Service = SttpBackend[BlockingTask, ZStream[Blocking, Throwable, Byte], WebSocketHandler]

/**
Expand All @@ -32,9 +32,7 @@ package object zio {
* Known exceptions are converted to one of [[SttpClientException]]. Other exceptions are kept unchanged.
*/
def send[T](request: Request[T, Nothing]): ZIO[SttpClient with Blocking, Throwable, Response[T]] =
ZIO.accessM(env =>
env.get[SttpBackend[BlockingTask, ZStream[Blocking, Throwable, Byte], WebSocketHandler]].send(request)
)
ZIO.accessM(env => env.get[Service].send(request))

/**
* Opens a websocket. Only requests for which the method & URI are specified can be sent.
Expand All @@ -51,10 +49,6 @@ package object zio {
def openWebsocket[T, WS_RESULT](
request: Request[T, Nothing]
): ZIO[SttpClient with Blocking, Throwable, WebSocketResponse[WebSocket[BlockingTask]]] =
ZioWebSocketHandler().flatMap(handler =>
ZIO.accessM(env =>
env.get[SttpBackend[BlockingTask, ZStream[Blocking, Throwable, Byte], WebSocketHandler]].openWebsocket(request, handler)
)
)
ZioWebSocketHandler().flatMap(handler => ZIO.accessM(env => env.get[Service].openWebsocket(request, handler)))
}
}

0 comments on commit cbb0223

Please sign in to comment.