Skip to content

Commit

Permalink
Refactor: refactored API
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoog committed Mar 8, 2024
1 parent 4959a18 commit 98e6f27
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
32 changes: 0 additions & 32 deletions runtime/module/reactive.go

This file was deleted.

32 changes: 32 additions & 0 deletions runtime/module/reactive_module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package module

import (
"github.com/iotaledger/hive.go/ds/reactive"
"github.com/iotaledger/hive.go/log"
)

// ReactiveModule defines the interface of a reactive module.
type ReactiveModule interface {
// ConstructedEvent is the getter for an Event that is triggered when the module was constructed.
ConstructedEvent() reactive.Event

// InitializedEvent is the getter for an Event that is triggered when the module was initialized.
InitializedEvent() reactive.Event

// ShutdownEvent is the getter for an Event that is triggered when the module begins its shutdown process.
ShutdownEvent() reactive.Event

// StoppedEvent is the getter for an Event that is triggered when the module finishes its shutdown process.
StoppedEvent() reactive.Event

// NewSubModule creates a new reactive submodule with the given name.
NewSubModule(name string) ReactiveModule

// Logger is the logger of the module.
log.Logger
}

// NewReactiveModule creates a new ReactiveModule with the given logger.
func NewReactiveModule(logger log.Logger) ReactiveModule {
return newReactiveModule(logger)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"github.com/iotaledger/hive.go/log"
)

// reactiveImpl is the default implementation of a reactive module.
type reactiveImpl struct {
// reactiveModule is the default implementation of a ReactiveModule.
type reactiveModule struct {
// constructed is an Event that is triggered when the module was constructed.
constructed reactive.Event

Expand All @@ -23,9 +23,9 @@ type reactiveImpl struct {
log.Logger
}

// newReactiveImpl creates a new reactive module with the given logger.
func newReactiveImpl(logger log.Logger) *reactiveImpl {
return &reactiveImpl{
// newReactiveModule creates a new reactive module with the given logger.
func newReactiveModule(logger log.Logger) *reactiveModule {
return &reactiveModule{
constructed: reactive.NewEvent(),
initialized: reactive.NewEvent(),
shutdown: reactive.NewEvent(),
Expand All @@ -34,30 +34,30 @@ func newReactiveImpl(logger log.Logger) *reactiveImpl {
}
}

// Constructed is the getter for an Event that is triggered when the module was constructed.
func (r *reactiveImpl) Constructed() reactive.Event {
// ConstructedEvent is the getter for an Event that is triggered when the module was constructed.
func (r *reactiveModule) ConstructedEvent() reactive.Event {
return r.constructed
}

// Initialized is the getter for an Event that is triggered when the module was initialized.
func (r *reactiveImpl) Initialized() reactive.Event {
// InitializedEvent is the getter for an Event that is triggered when the module was initialized.
func (r *reactiveModule) InitializedEvent() reactive.Event {
return r.stopped
}

// Shutdown is the getter for an Event that is triggered when the module begins its shutdown process.
func (r *reactiveImpl) Shutdown() reactive.Event {
// ShutdownEvent is the getter for an Event that is triggered when the module begins its shutdown process.
func (r *reactiveModule) ShutdownEvent() reactive.Event {
return r.shutdown
}

// Stopped is the getter for an Event that is triggered when the module finishes its shutdown process.
func (r *reactiveImpl) Stopped() reactive.Event {
// StoppedEvent is the getter for an Event that is triggered when the module finishes its shutdown process.
func (r *reactiveModule) StoppedEvent() reactive.Event {
return r.stopped
}

// NewSubModule creates a new reactive submodule with the given name.
func (r *reactiveImpl) NewSubModule(name string) Reactive {
func (r *reactiveModule) NewSubModule(name string) ReactiveModule {
childLogger := r.NewChildLogger(name)
r.shutdown.OnTrigger(childLogger.UnsubscribeFromParentLogger)

return NewReactive(childLogger)
return NewReactiveModule(childLogger)
}

0 comments on commit 98e6f27

Please sign in to comment.