github.com/haraldrudell/parl@v0.4.176/pnet/thread-handle.go (about)

     1  /*
     2  © 2024–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package pnet
     7  
     8  import (
     9  	"fmt"
    10  	"net"
    11  )
    12  
    13  // ConnectionReceiver is used by [ThreadSource] to
    14  // process or cancel connections
    15  //   - ThreadSource provides ahead notice so that any
    16  //     thread-strategy can be implemented
    17  //   - either Handle or Shutdown or both must be invoked
    18  //     for all obtained ConnectionReceivers
    19  type ConnectionReceiver[C net.Conn] interface {
    20  	// Handle operates on and closes a connection
    21  	//	- may only be invoked once or panic
    22  	//	- the provided connection is guaranteed to be closed
    23  	//	- thread-safe
    24  	//	- Handle invocations after Shutdown immediately
    25  	//		close the connection
    26  	Handle(conn C)
    27  	// may be invoked at any time: before, after or in lieu of Handle
    28  	//	- on Shutdown return, any provided connection has been
    29  	//		closed and all resources have been released
    30  	//	- thread-safe idempotent
    31  	Shutdown()
    32  	fmt.Stringer
    33  }