forked from Silverfish/proton-bridge
feat(GODT-2500): Reorganise async methods.
This commit is contained in:
@ -23,20 +23,20 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ProtonMail/gluon/queue"
|
||||
"github.com/ProtonMail/gluon/async"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/events"
|
||||
)
|
||||
|
||||
type eventCollector struct {
|
||||
events map[reflect.Type]*queue.QueuedChannel[events.Event]
|
||||
fwdCh []*queue.QueuedChannel[events.Event]
|
||||
events map[reflect.Type]*async.QueuedChannel[events.Event]
|
||||
fwdCh []*async.QueuedChannel[events.Event]
|
||||
lock sync.Mutex
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
func newEventCollector() *eventCollector {
|
||||
return &eventCollector{
|
||||
events: make(map[reflect.Type]*queue.QueuedChannel[events.Event]),
|
||||
events: make(map[reflect.Type]*async.QueuedChannel[events.Event]),
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ func (c *eventCollector) collectFrom(eventCh <-chan events.Event) <-chan events.
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
fwdCh := queue.NewQueuedChannel[events.Event](0, 0, queue.NoopPanicHandler{})
|
||||
fwdCh := async.NewQueuedChannel[events.Event](0, 0, async.NoopPanicHandler{})
|
||||
|
||||
c.fwdCh = append(c.fwdCh, fwdCh)
|
||||
|
||||
@ -87,7 +87,7 @@ func (c *eventCollector) push(event events.Event) {
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if _, ok := c.events[reflect.TypeOf(event)]; !ok {
|
||||
c.events[reflect.TypeOf(event)] = queue.NewQueuedChannel[events.Event](0, 0, queue.NoopPanicHandler{})
|
||||
c.events[reflect.TypeOf(event)] = async.NewQueuedChannel[events.Event](0, 0, async.NoopPanicHandler{})
|
||||
}
|
||||
|
||||
c.events[reflect.TypeOf(event)].Enqueue(event)
|
||||
@ -102,7 +102,7 @@ func (c *eventCollector) getEventCh(ofType events.Event) <-chan events.Event {
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if _, ok := c.events[reflect.TypeOf(ofType)]; !ok {
|
||||
c.events[reflect.TypeOf(ofType)] = queue.NewQueuedChannel[events.Event](0, 0, queue.NoopPanicHandler{})
|
||||
c.events[reflect.TypeOf(ofType)] = async.NewQueuedChannel[events.Event](0, 0, async.NoopPanicHandler{})
|
||||
}
|
||||
|
||||
return c.events[reflect.TypeOf(ofType)].GetChannel()
|
||||
|
||||
@ -29,8 +29,8 @@ import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/ProtonMail/gluon/async"
|
||||
"github.com/ProtonMail/gluon/imap"
|
||||
"github.com/ProtonMail/gluon/queue"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/bridge"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/constants"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/cookies"
|
||||
@ -108,7 +108,7 @@ func (t *testCtx) initBridge() (<-chan events.Event, error) {
|
||||
}
|
||||
|
||||
// Create the vault.
|
||||
vault, corrupt, err := vault.New(vaultDir, gluonCacheDir, t.storeKey, queue.NoopPanicHandler{})
|
||||
vault, corrupt, err := vault.New(vaultDir, gluonCacheDir, t.storeKey, async.NoopPanicHandler{})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not create vault: %w", err)
|
||||
} else if corrupt {
|
||||
@ -200,7 +200,7 @@ func (t *testCtx) initFrontendService(eventCh <-chan events.Event) error {
|
||||
t.mocks.Autostarter.EXPECT().IsEnabled().AnyTimes()
|
||||
|
||||
service, err := frontend.NewService(
|
||||
new(mockCrashHandler),
|
||||
&async.NoopPanicHandler{},
|
||||
new(mockRestarter),
|
||||
t.locator,
|
||||
t.bridge,
|
||||
@ -301,7 +301,7 @@ func (t *testCtx) initFrontendClient() error {
|
||||
return fmt.Errorf("could not start event stream: %w", err)
|
||||
}
|
||||
|
||||
eventCh := queue.NewQueuedChannel[*frontend.StreamEvent](0, 0, queue.NoopPanicHandler{})
|
||||
eventCh := async.NewQueuedChannel[*frontend.StreamEvent](0, 0, async.NoopPanicHandler{})
|
||||
|
||||
go func() {
|
||||
defer eventCh.CloseAndDiscardQueued()
|
||||
@ -343,10 +343,6 @@ func (t *testCtx) closeFrontendClient() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type mockCrashHandler struct{}
|
||||
|
||||
func (m *mockCrashHandler) HandlePanic() {}
|
||||
|
||||
type mockRestarter struct{}
|
||||
|
||||
func (m *mockRestarter) Set(restart, crash bool) {}
|
||||
|
||||
@ -23,7 +23,7 @@ import (
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/ProtonMail/gluon/queue"
|
||||
"github.com/ProtonMail/gluon/async"
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
"github.com/bradenaw/juniper/stream"
|
||||
@ -114,7 +114,7 @@ func (t *testCtx) withAddrKR(
|
||||
return err
|
||||
}
|
||||
|
||||
_, addrKRs, err := proton.Unlock(user, addr, keyPass, queue.NoopPanicHandler{})
|
||||
_, addrKRs, err := proton.Unlock(user, addr, keyPass, async.NoopPanicHandler{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/Masterminds/semver/v3"
|
||||
"github.com/ProtonMail/gluon/queue"
|
||||
"github.com/ProtonMail/gluon/async"
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/go-proton-api/server"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/bridge"
|
||||
@ -141,7 +141,7 @@ type testCtx struct {
|
||||
// client holds the gRPC frontend client under test.
|
||||
client frontend.BridgeClient
|
||||
clientConn *grpc.ClientConn
|
||||
clientEventCh *queue.QueuedChannel[*frontend.StreamEvent]
|
||||
clientEventCh *async.QueuedChannel[*frontend.StreamEvent]
|
||||
|
||||
// These maps hold test objects created during the test.
|
||||
userByID map[string]*testUser
|
||||
|
||||
Reference in New Issue
Block a user