statemachine: don't force users to see reflect
This commit is contained in:
parent
05edf50931
commit
23472aa4f2
@ -25,12 +25,12 @@ type StateGroup struct {
|
|||||||
sms map[datastore.Key]*StateMachine
|
sms map[datastore.Key]*StateMachine
|
||||||
}
|
}
|
||||||
|
|
||||||
// stateType: T - (reflect.TypeOf(MyStateStruct{}))
|
// stateType: T - (MyStateStruct{})
|
||||||
func New(ds datastore.Datastore, hnd StateHandler, stateType reflect.Type) *StateGroup {
|
func New(ds datastore.Datastore, hnd StateHandler, stateType interface{}) *StateGroup {
|
||||||
return &StateGroup{
|
return &StateGroup{
|
||||||
sts: statestore.New(ds),
|
sts: statestore.New(ds),
|
||||||
hnd: hnd,
|
hnd: hnd,
|
||||||
stateType: stateType,
|
stateType: reflect.TypeOf(stateType),
|
||||||
|
|
||||||
sms: map[datastore.Key]*StateMachine{},
|
sms: map[datastore.Key]*StateMachine{},
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package statemachine
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ipfs/go-datastore"
|
"github.com/ipfs/go-datastore"
|
||||||
@ -67,7 +66,7 @@ func TestBasic(t *testing.T) {
|
|||||||
|
|
||||||
th := &testHandler{t: t, done: make(chan struct{}), proceed: make(chan struct{})}
|
th := &testHandler{t: t, done: make(chan struct{}), proceed: make(chan struct{})}
|
||||||
close(th.proceed)
|
close(th.proceed)
|
||||||
smm := New(ds, th, reflect.TypeOf(TestState{}))
|
smm := New(ds, th, TestState{})
|
||||||
|
|
||||||
if err := smm.Send(uint64(2), &TestEvent{A: "start"}); err != nil {
|
if err := smm.Send(uint64(2), &TestEvent{A: "start"}); err != nil {
|
||||||
t.Fatalf("%+v", err)
|
t.Fatalf("%+v", err)
|
||||||
@ -82,7 +81,7 @@ func TestPersist(t *testing.T) {
|
|||||||
ds := datastore.NewMapDatastore()
|
ds := datastore.NewMapDatastore()
|
||||||
|
|
||||||
th := &testHandler{t: t, done: make(chan struct{}), proceed: make(chan struct{})}
|
th := &testHandler{t: t, done: make(chan struct{}), proceed: make(chan struct{})}
|
||||||
smm := New(ds, th, reflect.TypeOf(TestState{}))
|
smm := New(ds, th, TestState{})
|
||||||
|
|
||||||
if err := smm.Send(uint64(2), &TestEvent{A: "start"}); err != nil {
|
if err := smm.Send(uint64(2), &TestEvent{A: "start"}); err != nil {
|
||||||
t.Fatalf("%+v", err)
|
t.Fatalf("%+v", err)
|
||||||
@ -93,7 +92,7 @@ func TestPersist(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
smm = New(ds, th, reflect.TypeOf(TestState{}))
|
smm = New(ds, th, TestState{})
|
||||||
if err := smm.Send(uint64(2), &TestEvent{A: "restart"}); err != nil {
|
if err := smm.Send(uint64(2), &TestEvent{A: "restart"}); err != nil {
|
||||||
t.Fatalf("%+v", err)
|
t.Fatalf("%+v", err)
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package storage
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"reflect"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
@ -86,7 +85,7 @@ func NewMiner(api storageMinerApi, addr address.Address, h host.Host, ds datasto
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: separate sector stuff from miner struct
|
// TODO: separate sector stuff from miner struct
|
||||||
m.sectors = statemachine.New(namespace.Wrap(ds, datastore.NewKey(SectorStorePrefix)), m, reflect.TypeOf(SectorInfo{}))
|
m.sectors = statemachine.New(namespace.Wrap(ds, datastore.NewKey(SectorStorePrefix)), m, SectorInfo{})
|
||||||
|
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user