mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-18 08:06:59 +00:00
feat(GODT-2585): Server Manager
Add a dedicated go-routine whose sole responsibility is to manage the life time of the IMAP and SMTP servers and their listeners. The current implementation behaves the same way as the previous state. The new behavior will be implemented in a follow MR.
This commit is contained in:
21
cpc/cpc.go
21
cpc/cpc.go
@ -20,6 +20,7 @@ package cpc
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var ErrRequestHasNoReply = errors.New("request has no reply channel")
|
||||
@ -94,6 +95,10 @@ func (c *CPC) Receive(ctx context.Context, f func(context.Context, *Request)) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CPC) ReceiveCh() <-chan *Request {
|
||||
return c.request
|
||||
}
|
||||
|
||||
func (c *CPC) Close() {
|
||||
close(c.request)
|
||||
}
|
||||
@ -108,6 +113,22 @@ func (c *CPC) SendWithReply(ctx context.Context, value any) (any, error) {
|
||||
return c.executeReplyImpl(ctx, NewRequest(value))
|
||||
}
|
||||
|
||||
func SendWithReplyType[T any](ctx context.Context, c *CPC, value any) (T, error) {
|
||||
val, err := c.executeReplyImpl(ctx, NewRequest(value))
|
||||
if err != nil {
|
||||
var t T
|
||||
return t, err
|
||||
}
|
||||
|
||||
switch vt := val.(type) {
|
||||
case T:
|
||||
return vt, nil
|
||||
default:
|
||||
var t T
|
||||
return t, fmt.Errorf("reply type does not match")
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CPC) executeNoReplyImpl(ctx context.Context, request *Request) error {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
||||
Reference in New Issue
Block a user