components: allow access across goroutines
This commit is contained in:
parent
a8da3f70eb
commit
d7110dd63c
1 changed files with 2 additions and 5 deletions
|
|
@ -3,7 +3,6 @@ package wisski
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/component"
|
"github.com/FAU-CDI/wisski-distillery/internal/component"
|
||||||
|
|
@ -20,9 +19,9 @@ import (
|
||||||
|
|
||||||
// components holds the various components of the distillery
|
// components holds the various components of the distillery
|
||||||
// It is inlined into the [Distillery] struct, and initialized using [makeComponent].
|
// It is inlined into the [Distillery] struct, and initialized using [makeComponent].
|
||||||
|
//
|
||||||
|
// The caller is responsible for syncronizing access across multiple goroutines.
|
||||||
type components struct {
|
type components struct {
|
||||||
// m protects the fields below
|
|
||||||
m sync.Mutex
|
|
||||||
|
|
||||||
// installable components
|
// installable components
|
||||||
web *web.Web
|
web *web.Web
|
||||||
|
|
@ -47,8 +46,6 @@ type components struct {
|
||||||
//
|
//
|
||||||
// makeComponent returns the new or existing component instance
|
// makeComponent returns the new or existing component instance
|
||||||
func makeComponent[C component.Component](dis *Distillery, field *C, init func(C)) C {
|
func makeComponent[C component.Component](dis *Distillery, field *C, init func(C)) C {
|
||||||
dis.components.m.Lock()
|
|
||||||
defer dis.components.m.Unlock()
|
|
||||||
|
|
||||||
// get the typeof C and make sure that it is a pointer type!
|
// get the typeof C and make sure that it is a pointer type!
|
||||||
typC := reflect.TypeOf((*C)(nil)).Elem()
|
typC := reflect.TypeOf((*C)(nil)).Elem()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue