Skip to content

Commit

Permalink
Feat: Add reactive Module
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoog committed Oct 9, 2023
1 parent 3b7699b commit 9dd2605
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 16 deletions.
1 change: 1 addition & 0 deletions log/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21
require (
github.com/iotaledger/hive.go/ds v0.0.0-20230918225815-75359a468439
github.com/iotaledger/hive.go/lo v0.0.0-20230829145721-3041a551a2dd
github.com/iotaledger/hive.go/objectstorage v0.0.0-20230629181801-64c530ff9d15
)

require (
Expand Down
2 changes: 2 additions & 0 deletions log/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/iotaledger/hive.go/ierrors v0.0.0-20230829145721-3041a551a2dd h1:rkTr
github.com/iotaledger/hive.go/ierrors v0.0.0-20230829145721-3041a551a2dd/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8=
github.com/iotaledger/hive.go/lo v0.0.0-20230829145721-3041a551a2dd h1:O9ka/40xr6k+jjEYuwK6Y/AxB/6phoP4YesYkIhesx8=
github.com/iotaledger/hive.go/lo v0.0.0-20230829145721-3041a551a2dd/go.mod h1:/LERu5vqcessCqr40Wxmbx4x0bbymsK7GuL+TK/ckKo=
github.com/iotaledger/hive.go/objectstorage v0.0.0-20230629181801-64c530ff9d15 h1:jiQzzYPHqDNleU5tLpKHETF39rUdabs8dgHbrtJ1urM=
github.com/iotaledger/hive.go/objectstorage v0.0.0-20230629181801-64c530ff9d15/go.mod h1:E7/slsvlTsSP+laCKWbBOmSPg83UTh9mPm8ostFOlv4=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230829145721-3041a551a2dd h1:LODitqdRE4Bw++Lc/ANEA3l6/sK05WT3eWvZ4Q1rK4E=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230829145721-3041a551a2dd/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
Expand Down
9 changes: 5 additions & 4 deletions runtime/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ go 1.21
require (
github.com/fjl/memsize v0.0.1
github.com/iotaledger/hive.go/constraints v0.0.0-20230829145823-fdcc6f1afb61
github.com/iotaledger/hive.go/ds v0.0.0-20230829145823-fdcc6f1afb61
github.com/iotaledger/hive.go/ds v0.0.0-20230918225815-75359a468439
github.com/iotaledger/hive.go/ierrors v0.0.0-20230829145823-fdcc6f1afb61
github.com/iotaledger/hive.go/lo v0.0.0-20230829145823-fdcc6f1afb61
github.com/iotaledger/hive.go/log v0.0.0-20231009161204-3b7699bf3ba2
github.com/iotaledger/hive.go/stringify v0.0.0-20230829145823-fdcc6f1afb61
github.com/pelletier/go-toml/v2 v2.1.0
github.com/sasha-s/go-deadlock v0.3.1
Expand All @@ -16,14 +17,14 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/ethereum/go-ethereum v1.12.2 // indirect
github.com/ethereum/go-ethereum v1.13.1 // indirect
github.com/iancoleman/orderedmap v0.3.0 // indirect
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230829145823-fdcc6f1afb61 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/petermattis/goid v0.0.0-20230808133559-b036b712a89b // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/sys v0.12.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
26 changes: 14 additions & 12 deletions runtime/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 h1:HbphB4TFFXpv7MNrT52FGrrgVXF1owhMVTHFZIlnvd4=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0/go.mod h1:DZGJHZMqrU4JJqFAWUS2UO1+lbSKsdiOoYi9Zzey7Fc=
github.com/ethereum/go-ethereum v1.12.2 h1:eGHJ4ij7oyVqUQn48LBz3B7pvQ8sV0wGJiIE6gDq/6Y=
github.com/ethereum/go-ethereum v1.12.2/go.mod h1:1cRAEV+rp/xX0zraSCBnu9Py3HQ+geRMj3HdR+k0wfI=
github.com/ethereum/go-ethereum v1.13.1 h1:UF2FaUKPIy5jeZk3X06ait3y2Q4wI+vJ1l7+UARp+60=
github.com/ethereum/go-ethereum v1.13.1/go.mod h1:xHQKzwkHSl0gnSjZK1mWa06XEdm9685AHqhRknOzqGQ=
github.com/fjl/memsize v0.0.1 h1:+zhkb+dhUgx0/e+M8sF0QqiouvMQUiKR+QYvdxIOKcQ=
github.com/fjl/memsize v0.0.1/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o=
Expand All @@ -16,18 +16,20 @@ github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJ
github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE=
github.com/iotaledger/hive.go/constraints v0.0.0-20230829145823-fdcc6f1afb61 h1:JxCyAh6yj/AoDszB2v2fuDCKaW9tLmuPKzZTClWRqK8=
github.com/iotaledger/hive.go/constraints v0.0.0-20230829145823-fdcc6f1afb61/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s=
github.com/iotaledger/hive.go/ds v0.0.0-20230829145823-fdcc6f1afb61 h1:VLXGimSbMIQrXcv07Cgmy6GnJp7h3HB0ciIT+l1gsbw=
github.com/iotaledger/hive.go/ds v0.0.0-20230829145823-fdcc6f1afb61/go.mod h1:G4azdfQMwAkSU5lHZNRAdGfRoLHNHF4+DfCudWTTKF8=
github.com/iotaledger/hive.go/ds v0.0.0-20230918225815-75359a468439 h1:Rf03eqMxZEkg9Oytc+WtqiHDy6gXH+8c4ZitIfjnBLY=
github.com/iotaledger/hive.go/ds v0.0.0-20230918225815-75359a468439/go.mod h1:ZrqsjIJS2QCgGp7Ki+l4hWJQgzfBObUCemb5Upwlx18=
github.com/iotaledger/hive.go/ierrors v0.0.0-20230829145823-fdcc6f1afb61 h1:TmZ0kYdD+5pS3KLUTRLtt+VqfIWe1dBAmb2kLGLRBZc=
github.com/iotaledger/hive.go/ierrors v0.0.0-20230829145823-fdcc6f1afb61/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8=
github.com/iotaledger/hive.go/lo v0.0.0-20230829145823-fdcc6f1afb61 h1:eraNeQ5KKQpVJkKs4Ij/3eeVJfyJQ/PzZUAhnAkT2MI=
github.com/iotaledger/hive.go/lo v0.0.0-20230829145823-fdcc6f1afb61/go.mod h1:/LERu5vqcessCqr40Wxmbx4x0bbymsK7GuL+TK/ckKo=
github.com/iotaledger/hive.go/log v0.0.0-20231009161204-3b7699bf3ba2 h1:rrhdEp/FxX4I/NPNLuRD4nkddBoXHPD3XzK2eGh79NQ=
github.com/iotaledger/hive.go/log v0.0.0-20231009161204-3b7699bf3ba2/go.mod h1:UF7PzlWdZ2H0Hkxrt4AgJmNVeMXUJzw4RwbHpib1DB0=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230829145823-fdcc6f1afb61 h1:dOMCg/KYm/f/ZWJfNCMgJRGJJZ3SY4NZiho1FuQOnDI=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230829145823-fdcc6f1afb61/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I=
github.com/iotaledger/hive.go/stringify v0.0.0-20230829145823-fdcc6f1afb61 h1:cnps08Hd+bV9DccRlSGo/5wMyxeBsLEIWDJyguDY7Js=
github.com/iotaledger/hive.go/stringify v0.0.0-20230829145823-fdcc6f1afb61/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
Expand All @@ -50,13 +52,13 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
44 changes: 44 additions & 0 deletions runtime/module/reactive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package module

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

// ReactiveModule is a trait that exposes logging functionality and lifecycle related Events, that can be used to create
// a modular architecture where different modules can wait for each other to reach certain states.
type ReactiveModule struct {
// Constructed is triggered when the module was constructed.
Constructed reactive.Event

// Initialized is triggered when the module was initialized.
Initialized reactive.Event

// Shutdown is triggered when the module begins its shutdown process.
Shutdown reactive.Event

// Stopped is triggered when the module finishes its shutdown process.
Stopped reactive.Event

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

// 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(),
Stopped: reactive.NewEvent(),
Logger: logger,
}
}

// NewReactiveSubModule creates a new reactive submodule with the given name.
func (r *ReactiveModule) NewReactiveSubModule(name string) *ReactiveModule {
childLogger, unsubscribe := r.NewChildLogger(name)
r.Shutdown.OnTrigger(unsubscribe)

return NewReactiveModule(childLogger)
}

0 comments on commit 9dd2605

Please sign in to comment.