-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(proposal): subscriber interface/basic impl
Signed-off-by: Mark Phelps <[email protected]>
- Loading branch information
1 parent
cdc7e07
commit 871e256
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package logger | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/get-glu/glu/pkg/core" | ||
"github.com/google/uuid" | ||
) | ||
|
||
type Event struct { | ||
Phase core.Descriptor | ||
State core.State | ||
// TODO: event type | ||
} | ||
|
||
// Subscriber is a type that can receive events from a phase logger. | ||
type Subscriber interface { | ||
// OnEvent is called when a new event is received. | ||
OnEvent(ctx context.Context, event Event) error | ||
} | ||
|
||
// Subscription represents an active subscription to a phase logger. | ||
type Subscription struct { | ||
ID uuid.UUID | ||
Cancel context.CancelFunc | ||
} | ||
|
||
// Subscribable extends PhaseLogger with subscription functionality. | ||
type Subscribable[R core.Resource] interface { | ||
PhaseLogger[R] | ||
|
||
// Subscribe returns a new subscription to the phase logger. | ||
Subscribe(ctx context.Context, subscriber Subscriber) (*Subscription, error) | ||
// Unsubscribe cancels a subscription. | ||
Unsubscribe(ctx context.Context, id uuid.UUID) error | ||
} |