thinking 1 level
This commit is contained in:
parent
dd81525b9f
commit
6e7f43dfdd
14
brain.go
14
brain.go
|
@ -2,14 +2,26 @@ package brain
|
|||
|
||||
import (
|
||||
context "context"
|
||||
"log"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/474420502/brain/pb"
|
||||
)
|
||||
|
||||
// UnimplementedBrainServiceServer can be embedded to have forward compatible implementations.
|
||||
type BrainService struct {
|
||||
IsRunningMain atomic.Int64
|
||||
}
|
||||
|
||||
func (*BrainService) Add(context.Context, *pb.Request) (*pb.Response, error) {
|
||||
func (brain *BrainService) Main() {
|
||||
if brain.IsRunningMain.CompareAndSwap(0, 1) {
|
||||
defer brain.IsRunningMain.Swap(0)
|
||||
|
||||
} else {
|
||||
log.Println("Main is Running")
|
||||
}
|
||||
}
|
||||
|
||||
func (*BrainService) Add(cxt context.Context, req *pb.Request) (*pb.Response, error) {
|
||||
return &pb.Response{Code: 200}, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user