Skip to content

Commit

Permalink
Support "protocols" and provide the serve method
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Jul 2, 2024
1 parent 39509ac commit c8adf83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/nettlesome-core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ extension [RemoteType: Connectable](value: RemoteType)
infix def on [PortType](port: PortType): Endpoint[PortType] =
Endpoint(RemoteType.remote(value), port)

extension [PortType](port: PortType)
def serve[ProtocolType: Protocolic on PortType]
(handler: ProtocolType.Request ?=> ProtocolType.Response)
: ProtocolType.Server =
ProtocolType.server(port)(handler)

def internet[ResultType](online: Boolean)(block: Internet ?=> ResultType): ResultType =
block(using Internet(online))

def online(using internet: Internet): Boolean = internet.online

infix type on [Type <: { type On }, PortType] = Type { type On = PortType }
9 changes: 9 additions & 0 deletions src/core/nettlesome.Protocolic.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package nettlesome

trait Protocolic:
type Self
type On
type Request
type Response
type Server
def server(port: On)(lambda: Request ?=> Response): Server

0 comments on commit c8adf83

Please sign in to comment.