package states
import (
am "github.com/pancsta/asyncmachine-go/pkg/machine"
"github.com/pancsta/asyncmachine-go/pkg/states"
. "github.com/pancsta/asyncmachine-go/pkg/states/global"
)
type SharedStatesDef struct {
ErrNetworkTimeout string
ErrRpc string
ErrDelivery string
HandshakeDone string
Handshaking string
*states .BasicStatesDef
}
type SharedGroupsDef struct {
Handshake S
}
var SharedSchema = SchemaMerge (
states .BasicSchema ,
am .Schema {
s .ErrNetworkTimeout : {
Add : S {s .Exception },
Require : S {s .Exception },
},
s .ErrRpc : {
Add : S {s .Exception },
Require : S {s .Exception },
},
s .ErrDelivery : {
Add : S {s .Exception },
Require : S {s .Exception },
},
s .Handshaking : {
Require : S {s .Start },
Remove : g .Handshake ,
},
s .HandshakeDone : {
Require : S {s .Start },
Remove : g .Handshake ,
},
})
var (
s = am .NewStates (SharedStatesDef {})
g = am .NewStateGroups (SharedGroupsDef {
Handshake : S {s .Handshaking , s .HandshakeDone },
})
SharedStates = s
SharedGroups = g
)
type NetSourceStatesDef struct {
*am .StatesBase
ErrOnClient string
ErrProviding string
ErrSendPayload string
SendPayload string
}
var NetSourceSchema = SchemaMerge (
am .Schema {
ssNS .ErrOnClient : {Require : S {Exception }},
ssNS .ErrProviding : {Require : S {Exception }},
ssNS .ErrSendPayload : {Require : S {Exception }},
ssNS .SendPayload : {Multi : true },
})
var (
ssNS = am .NewStates (NetSourceStatesDef {})
NetSourceStates = ssNS
)
type ServerStatesDef struct {
Ready string
RpcStarting string
RpcReady string
ClientConnected string
HandshakeDone string
MetricSync string
*SharedStatesDef
}
type ServerGroupsDef struct {
*SharedGroupsDef
Rpc S
}
var ServerSchema = SchemaMerge (
SharedSchema ,
am .Schema {
ssS .ErrNetwork : {
Require : S {am .StateException },
Remove : S {ssS .ClientConnected },
},
ssS .HandshakeDone : StateAdd (
SharedSchema [ssS .HandshakeDone ],
am .State {
Require : S {ssS .ClientConnected },
Remove : S {Exception },
}),
ssS .Start : {Add : S {ssS .RpcStarting }},
ssS .Ready : {
Auto : true ,
Require : S {ssS .HandshakeDone , ssS .RpcReady },
},
ssS .RpcStarting : {
Require : S {ssS .Start },
Remove : sgS .Rpc ,
},
ssS .RpcReady : {
Require : S {ssS .Start },
Remove : sgS .Rpc ,
},
ssS .ClientConnected : {
Require : S {ssS .RpcReady },
},
ssS .MetricSync : {Multi : true },
})
var (
ssS = am .NewStates (ServerStatesDef {})
sgS = am .NewStateGroups (ServerGroupsDef {
Rpc : S {ssS .RpcStarting , ssS .RpcReady },
}, SharedGroups )
ServerStates = ssS
ServerGroups = sgS
)
type ClientStatesDef struct {
*am .StatesBase
RetryingCall string
CallRetryFailed string
RetryingConn string
ConnRetryFailed string
Ready string
HandshakeDone string
WorkerDelivering string
WorkerPayload string
MetricSync string
*SharedStatesDef
*states .ConnectedStatesDef
}
type ClientGroupsDef struct {
*SharedGroupsDef
*states .ConnectedGroupsDef
}
var ClientSchema = SchemaMerge (
SharedSchema ,
states .ConnectedSchema ,
am .Schema {
ssC .ErrNetwork : {
Require : S {am .StateException },
Remove : S {ssC .Connecting },
},
ssC .Start : {
Add : S {ssC .Connecting },
Remove : S {ssC .ConnRetryFailed },
},
ssC .Ready : {
Auto : true ,
Require : S {ssC .HandshakeDone },
},
ssC .Connected : StateAdd (
states .ConnectedSchema [states .ConnectedStates .Connected ],
am .State {
Remove : S {ssC .RetryingConn },
Add : S {ssC .Handshaking },
}),
ssC .Handshaking : StateAdd (
SharedSchema [s .Handshaking ],
am .State {
Require : S {ssC .Connected },
}),
ssC .HandshakeDone : am .StateAdd (
SharedSchema [ssC .HandshakeDone ], am .State {
Require : S {ssC .Connected },
}),
ssC .RetryingCall : {Require : S {ssC .Start }},
ssC .CallRetryFailed : {
Remove : S {ssC .RetryingCall },
Add : S {ssC .ErrNetwork , am .StateException },
},
ssC .RetryingConn : {Require : S {ssC .Start }},
ssC .ConnRetryFailed : {Remove : S {ssC .Start }},
ssC .WorkerDelivering : {
Multi : true ,
Require : S {ssC .Connected },
},
ssC .WorkerPayload : {
Multi : true ,
Require : S {ssC .Connected },
},
ssC .MetricSync : {Multi : true },
})
var (
ssC = am .NewStates (ClientStatesDef {})
sgC = am .NewStateGroups (ClientGroupsDef {}, states .ConnectedGroups ,
SharedGroups )
ClientStates = ssC
ClientGroups = sgC
)
type MuxStatesDef struct {
*am .StatesBase
Ready string
ClientConnected string
HasClients string
NewServerErr string
*states .BasicStatesDef
}
type MuxGroupsDef struct {
}
var MuxSchema = SchemaMerge (
states .BasicSchema ,
am .Schema {
ssD .Exception : {
Multi : true ,
Remove : S {ssS .Ready },
},
ssD .Ready : {
Require : S {ssS .Start },
},
ssD .ClientConnected : {
Multi : true ,
Require : states .S {ssD .Start },
},
ssD .HasClients : {Require : states .S {ssD .Start }},
ssD .NewServerErr : {},
})
var (
ssD = am .NewStates (MuxStatesDef {})
sgD = am .NewStateGroups (MuxGroupsDef {})
MuxStates = ssD
MuxGroups = sgD
)
type ConsumerStatesDef struct {
*am .StatesBase
Exception string
WorkerPayload string
}
var ConsumerSchema = am .Schema {
ssCo .WorkerPayload : {Multi : true },
}
type ConsumerHandlers interface {
WorkerPayloadState (e *am .Event )
}
var (
ssCo = am .NewStates (ConsumerStatesDef {})
ConsumerStates = ssCo
)
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .