|
@ -15,7 +15,7 @@ import ( |
|
|
type localClient struct { |
|
|
type localClient struct { |
|
|
service.BaseService |
|
|
service.BaseService |
|
|
|
|
|
|
|
|
mtx *tmsync.Mutex |
|
|
|
|
|
|
|
|
mtx *tmsync.RWMutex |
|
|
types.Application |
|
|
types.Application |
|
|
Callback |
|
|
Callback |
|
|
} |
|
|
} |
|
@ -26,22 +26,24 @@ var _ Client = (*localClient)(nil) |
|
|
// methods of the given app.
|
|
|
// methods of the given app.
|
|
|
//
|
|
|
//
|
|
|
// Both Async and Sync methods ignore the given context.Context parameter.
|
|
|
// Both Async and Sync methods ignore the given context.Context parameter.
|
|
|
func NewLocalClient(mtx *tmsync.Mutex, app types.Application) Client { |
|
|
|
|
|
|
|
|
func NewLocalClient(mtx *tmsync.RWMutex, app types.Application) Client { |
|
|
if mtx == nil { |
|
|
if mtx == nil { |
|
|
mtx = new(tmsync.Mutex) |
|
|
|
|
|
|
|
|
mtx = &tmsync.RWMutex{} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cli := &localClient{ |
|
|
cli := &localClient{ |
|
|
mtx: mtx, |
|
|
mtx: mtx, |
|
|
Application: app, |
|
|
Application: app, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cli.BaseService = *service.NewBaseService(nil, "localClient", cli) |
|
|
cli.BaseService = *service.NewBaseService(nil, "localClient", cli) |
|
|
return cli |
|
|
return cli |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (app *localClient) SetResponseCallback(cb Callback) { |
|
|
func (app *localClient) SetResponseCallback(cb Callback) { |
|
|
app.mtx.Lock() |
|
|
app.mtx.Lock() |
|
|
|
|
|
defer app.mtx.Unlock() |
|
|
app.Callback = cb |
|
|
app.Callback = cb |
|
|
app.mtx.Unlock() |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO: change types.Application to include Error()?
|
|
|
// TODO: change types.Application to include Error()?
|
|
@ -65,8 +67,8 @@ func (app *localClient) EchoAsync(ctx context.Context, msg string) (*ReqRes, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (app *localClient) InfoAsync(ctx context.Context, req types.RequestInfo) (*ReqRes, error) { |
|
|
func (app *localClient) InfoAsync(ctx context.Context, req types.RequestInfo) (*ReqRes, error) { |
|
|
app.mtx.Lock() |
|
|
|
|
|
defer app.mtx.Unlock() |
|
|
|
|
|
|
|
|
app.mtx.RLock() |
|
|
|
|
|
defer app.mtx.RUnlock() |
|
|
|
|
|
|
|
|
res := app.Application.Info(req) |
|
|
res := app.Application.Info(req) |
|
|
return app.callback( |
|
|
return app.callback( |
|
@ -98,8 +100,8 @@ func (app *localClient) CheckTxAsync(ctx context.Context, req types.RequestCheck |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (app *localClient) QueryAsync(ctx context.Context, req types.RequestQuery) (*ReqRes, error) { |
|
|
func (app *localClient) QueryAsync(ctx context.Context, req types.RequestQuery) (*ReqRes, error) { |
|
|
app.mtx.Lock() |
|
|
|
|
|
defer app.mtx.Unlock() |
|
|
|
|
|
|
|
|
app.mtx.RLock() |
|
|
|
|
|
defer app.mtx.RUnlock() |
|
|
|
|
|
|
|
|
res := app.Application.Query(req) |
|
|
res := app.Application.Query(req) |
|
|
return app.callback( |
|
|
return app.callback( |
|
@ -213,8 +215,8 @@ func (app *localClient) EchoSync(ctx context.Context, msg string) (*types.Respon |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (app *localClient) InfoSync(ctx context.Context, req types.RequestInfo) (*types.ResponseInfo, error) { |
|
|
func (app *localClient) InfoSync(ctx context.Context, req types.RequestInfo) (*types.ResponseInfo, error) { |
|
|
app.mtx.Lock() |
|
|
|
|
|
defer app.mtx.Unlock() |
|
|
|
|
|
|
|
|
app.mtx.RLock() |
|
|
|
|
|
defer app.mtx.RUnlock() |
|
|
|
|
|
|
|
|
res := app.Application.Info(req) |
|
|
res := app.Application.Info(req) |
|
|
return &res, nil |
|
|
return &res, nil |
|
@ -247,8 +249,8 @@ func (app *localClient) QuerySync( |
|
|
ctx context.Context, |
|
|
ctx context.Context, |
|
|
req types.RequestQuery, |
|
|
req types.RequestQuery, |
|
|
) (*types.ResponseQuery, error) { |
|
|
) (*types.ResponseQuery, error) { |
|
|
app.mtx.Lock() |
|
|
|
|
|
defer app.mtx.Unlock() |
|
|
|
|
|
|
|
|
app.mtx.RLock() |
|
|
|
|
|
defer app.mtx.RUnlock() |
|
|
|
|
|
|
|
|
res := app.Application.Query(req) |
|
|
res := app.Application.Query(req) |
|
|
return &res, nil |
|
|
return &res, nil |
|
|