Skip to content

Commit 72d7457

Browse files
committed
api: left only asynchronous Connection.Do(request)
The patch deletes synchronous Connection.Do and Connection.DoTyped and renames an asynchronous Connection.DoAsync to Connection.Do. There are several reasons for this: 1. It helps to make the public API shorter. 2. It makes the asynchronous essence of the connector is more clear. 3. It helps not to spread the unnecessary API to submodules. 4. We will have more freedom for changes in the future.
1 parent d04f8be commit 72d7457

11 files changed

+50
-100
lines changed

call_16_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestCallRequest(t *testing.T) {
3535
defer conn.Close()
3636

3737
req := NewCallRequest("simple_incr").Args([]interface{}{1})
38-
resp, err = conn.Do(req)
38+
resp, err = conn.Do(req).Get()
3939
if err != nil {
4040
t.Errorf("Failed to use Call")
4141
}

call_17_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestCallRequest(t *testing.T) {
3535
defer conn.Close()
3636

3737
req := NewCallRequest("simple_incr").Args([]interface{}{1})
38-
resp, err = conn.Do(req)
38+
resp, err = conn.Do(req).Get()
3939
if err != nil {
4040
t.Errorf("Failed to use Call")
4141
}

connection.go

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -988,29 +988,11 @@ func (conn *Connection) nextRequestId() (requestId uint32) {
988988
return atomic.AddUint32(&conn.requestId, 1)
989989
}
990990

991-
// Do verifies, sends the request and returns a response.
992-
//
993-
// An error is returned if the request was formed incorrectly, or failed to
994-
// communicate by the connection, or unable to decode the response.
995-
func (conn *Connection) Do(req Request) (*Response, error) {
996-
fut := conn.DoAsync(req)
997-
return fut.Get()
998-
}
999-
1000-
// DoTyped verifies, sends the request and fills the typed result.
1001-
//
1002-
// An error is returned if the request was formed incorrectly, or failed to
1003-
// communicate by the connection, or unable to decode the response.
1004-
func (conn *Connection) DoTyped(req Request, result interface{}) error {
1005-
fut := conn.DoAsync(req)
1006-
return fut.GetTyped(result)
1007-
}
1008-
1009-
// DoAsync verifies, sends the request and returns a future.
991+
// Do performs a request asynchronously on the connection.
1010992
//
1011993
// An error is returned if the request was formed incorrectly, or failed to
1012994
// create the future.
1013-
func (conn *Connection) DoAsync(req Request) *Future {
995+
func (conn *Connection) Do(req Request) *Future {
1014996
return conn.send(req)
1015997
}
1016998

connection_pool/connection_pool.go

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -524,34 +524,14 @@ func (connPool *ConnectionPool) EvalAsync(expr string, args interface{}, userMod
524524
return conn.EvalAsync(expr, args)
525525
}
526526

527-
// Do sends the request and returns a response.
528-
func (connPool *ConnectionPool) Do(req tarantool.Request, userMode Mode) (*tarantool.Response, error) {
529-
conn, err := connPool.getNextConnection(userMode)
530-
if err != nil {
531-
return nil, err
532-
}
533-
534-
return conn.Do(req)
535-
}
536-
537-
// DoTyped sends the request and fills the typed result.
538-
func (connPool *ConnectionPool) DoTyped(req tarantool.Request, result interface{}, userMode Mode) error {
539-
conn, err := connPool.getNextConnection(userMode)
540-
if err != nil {
541-
return err
542-
}
543-
544-
return conn.DoTyped(req, result)
545-
}
546-
547-
// DoAsync sends the request and returns a future.
548-
func (connPool *ConnectionPool) DoAsync(req tarantool.Request, userMode Mode) *tarantool.Future {
527+
// Do sends the request and returns a future.
528+
func (connPool *ConnectionPool) Do(req tarantool.Request, userMode Mode) *tarantool.Future {
549529
conn, err := connPool.getNextConnection(userMode)
550530
if err != nil {
551531
return newErrorFuture(err)
552532
}
553533

554-
return conn.DoAsync(req)
534+
return conn.Do(req)
555535
}
556536

557537
//

connection_pool/connection_pool_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,27 +1251,27 @@ func TestDo(t *testing.T) {
12511251

12521252
req := tarantool.NewPingRequest()
12531253
// ANY
1254-
resp, err := connPool.Do(req, connection_pool.ANY)
1254+
resp, err := connPool.Do(req, connection_pool.ANY).Get()
12551255
require.Nilf(t, err, "failed to Ping")
12561256
require.NotNilf(t, resp, "response is nil after Ping")
12571257

12581258
// RW
1259-
resp, err = connPool.Do(req, connection_pool.RW)
1259+
resp, err = connPool.Do(req, connection_pool.RW).Get()
12601260
require.Nilf(t, err, "failed to Ping")
12611261
require.NotNilf(t, resp, "response is nil after Ping")
12621262

12631263
// RO
1264-
resp, err = connPool.Do(req, connection_pool.RO)
1264+
resp, err = connPool.Do(req, connection_pool.RO).Get()
12651265
require.Nilf(t, err, "failed to Ping")
12661266
require.NotNilf(t, resp, "response is nil after Ping")
12671267

12681268
// PreferRW
1269-
resp, err = connPool.Do(req, connection_pool.PreferRW)
1269+
resp, err = connPool.Do(req, connection_pool.PreferRW).Get()
12701270
require.Nilf(t, err, "failed to Ping")
12711271
require.NotNilf(t, resp, "response is nil after Ping")
12721272

12731273
// PreferRO
1274-
resp, err = connPool.Do(req, connection_pool.PreferRO)
1274+
resp, err = connPool.Do(req, connection_pool.PreferRO).Get()
12751275
require.Nilf(t, err, "failed to Ping")
12761276
require.NotNilf(t, resp, "response is nil after Ping")
12771277
}

connection_pool/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ func ExampleConnectionPool_Do() {
539539

540540
// Ping a Tarantool instance to check connection.
541541
req := tarantool.NewPingRequest()
542-
resp, err := pool.Do(req, connection_pool.ANY)
542+
resp, err := pool.Do(req, connection_pool.ANY).Get()
543543
fmt.Println("Ping Code", resp.Code)
544544
fmt.Println("Ping Data", resp.Data)
545545
fmt.Println("Ping Error", err)

connector.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,5 @@ type Connector interface {
4242
Call17Async(functionName string, args interface{}) *Future
4343
EvalAsync(expr string, args interface{}) *Future
4444

45-
Do(req Request) (resp *Response, err error)
46-
DoTyped(req Request, result interface{}) (err error)
47-
DoAsync(req Request) (fut *Future)
45+
Do(req Request) (fut *Future)
4846
}

example_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func ExampleSelectRequest() {
133133
req := tarantool.NewSelectRequest(517).
134134
Limit(100).
135135
Key(tarantool.IntKey{1111})
136-
resp, err := conn.Do(req)
136+
resp, err := conn.Do(req).Get()
137137
if err != nil {
138138
fmt.Printf("error in do select request is %v", err)
139139
return
@@ -144,7 +144,7 @@ func ExampleSelectRequest() {
144144
Index("primary").
145145
Limit(100).
146146
Key(tarantool.IntKey{1111})
147-
fut := conn.DoAsync(req)
147+
fut := conn.Do(req)
148148
resp, err = fut.Get()
149149
if err != nil {
150150
fmt.Printf("error in do async select request is %v", err)
@@ -163,7 +163,7 @@ func ExampleUpdateRequest() {
163163
req := tarantool.NewUpdateRequest(517).
164164
Key(tarantool.IntKey{1111}).
165165
Operations(tarantool.NewOperations().Assign(1, "bye"))
166-
resp, err := conn.Do(req)
166+
resp, err := conn.Do(req).Get()
167167
if err != nil {
168168
fmt.Printf("error in do update request is %v", err)
169169
return
@@ -174,7 +174,7 @@ func ExampleUpdateRequest() {
174174
Index("primary").
175175
Key(tarantool.IntKey{1111}).
176176
Operations(tarantool.NewOperations().Assign(1, "hello"))
177-
fut := conn.DoAsync(req)
177+
fut := conn.Do(req)
178178
resp, err = fut.Get()
179179
if err != nil {
180180
fmt.Printf("error in do async update request is %v", err)
@@ -194,7 +194,7 @@ func ExampleUpsertRequest() {
194194
req = tarantool.NewUpsertRequest(517).
195195
Tuple([]interface{}{uint(1113), "first", "first"}).
196196
Operations(tarantool.NewOperations().Assign(1, "updated"))
197-
resp, err := conn.Do(req)
197+
resp, err := conn.Do(req).Get()
198198
if err != nil {
199199
fmt.Printf("error in do select upsert is %v", err)
200200
return
@@ -204,7 +204,7 @@ func ExampleUpsertRequest() {
204204
req = tarantool.NewUpsertRequest("test").
205205
Tuple([]interface{}{uint(1113), "second", "second"}).
206206
Operations(tarantool.NewOperations().Assign(2, "updated"))
207-
fut := conn.DoAsync(req)
207+
fut := conn.Do(req)
208208
resp, err = fut.Get()
209209
if err != nil {
210210
fmt.Printf("error in do async upsert request is %v", err)
@@ -215,7 +215,7 @@ func ExampleUpsertRequest() {
215215
req = tarantool.NewSelectRequest(517).
216216
Limit(100).
217217
Key(tarantool.IntKey{1113})
218-
resp, err = conn.Do(req)
218+
resp, err = conn.Do(req).Get()
219219
if err != nil {
220220
fmt.Printf("error in do select request is %v", err)
221221
return

multi/multi.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -482,17 +482,7 @@ func (connMulti *ConnectionMulti) EvalAsync(expr string, args interface{}) *tara
482482
return connMulti.getCurrentConnection().EvalAsync(expr, args)
483483
}
484484

485-
// Do sends the request and returns a response.
486-
func (connMulti *ConnectionMulti) Do(req tarantool.Request) (*tarantool.Response, error) {
485+
// Do sends the request and returns a future.
486+
func (connMulti *ConnectionMulti) Do(req tarantool.Request) *tarantool.Future {
487487
return connMulti.getCurrentConnection().Do(req)
488488
}
489-
490-
// DoTyped sends the request and fills the typed result.
491-
func (connMulti *ConnectionMulti) DoTyped(req tarantool.Request, result interface{}) error {
492-
return connMulti.getCurrentConnection().DoTyped(req, result)
493-
}
494-
495-
// DoAsync sends the request and returns a future.
496-
func (connMulti *ConnectionMulti) DoAsync(req tarantool.Request) *tarantool.Future {
497-
return connMulti.getCurrentConnection().DoAsync(req)
498-
}

request.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func fillPing(enc *msgpack.Encoder) error {
9797

9898
// Ping sends empty request to Tarantool to check connection.
9999
func (conn *Connection) Ping() (resp *Response, err error) {
100-
return conn.Do(NewPingRequest())
100+
return conn.Do(NewPingRequest()).Get()
101101
}
102102

103103
// Select performs select to box space.
@@ -311,44 +311,44 @@ func (conn *Connection) SelectAsync(space, index interface{}, offset, limit, ite
311311
Limit(limit).
312312
Iterator(iterator).
313313
Key(key)
314-
return conn.DoAsync(req)
314+
return conn.Do(req)
315315
}
316316

317317
// InsertAsync sends insert action to Tarantool and returns Future.
318318
// Tarantool will reject Insert when tuple with same primary key exists.
319319
func (conn *Connection) InsertAsync(space interface{}, tuple interface{}) *Future {
320320
req := NewInsertRequest(space).Tuple(tuple)
321-
return conn.DoAsync(req)
321+
return conn.Do(req)
322322
}
323323

324324
// ReplaceAsync sends "insert or replace" action to Tarantool and returns Future.
325325
// If tuple with same primary key exists, it will be replaced.
326326
func (conn *Connection) ReplaceAsync(space interface{}, tuple interface{}) *Future {
327327
req := NewReplaceRequest(space).Tuple(tuple)
328-
return conn.DoAsync(req)
328+
return conn.Do(req)
329329
}
330330

331331
// DeleteAsync sends deletion action to Tarantool and returns Future.
332332
// Future's result will contain array with deleted tuple.
333333
func (conn *Connection) DeleteAsync(space, index interface{}, key interface{}) *Future {
334334
req := NewDeleteRequest(space).Index(index).Key(key)
335-
return conn.DoAsync(req)
335+
return conn.Do(req)
336336
}
337337

338338
// Update sends deletion of a tuple by key and returns Future.
339339
// Future's result will contain array with updated tuple.
340340
func (conn *Connection) UpdateAsync(space, index interface{}, key, ops interface{}) *Future {
341341
req := NewUpdateRequest(space).Index(index).Key(key)
342342
req.ops = ops
343-
return conn.DoAsync(req)
343+
return conn.Do(req)
344344
}
345345

346346
// UpsertAsync sends "update or insert" action to Tarantool and returns Future.
347347
// Future's sesult will not contain any tuple.
348348
func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops interface{}) *Future {
349349
req := NewUpsertRequest(space).Tuple(tuple)
350350
req.ops = ops
351-
return conn.DoAsync(req)
351+
return conn.Do(req)
352352
}
353353

354354
// CallAsync sends a call to registered Tarantool function and returns Future.
@@ -357,36 +357,36 @@ func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops in
357357
// Otherwise, uses request code for Tarantool 1.6.
358358
func (conn *Connection) CallAsync(functionName string, args interface{}) *Future {
359359
req := NewCallRequest(functionName).Args(args)
360-
return conn.DoAsync(req)
360+
return conn.Do(req)
361361
}
362362

363363
// Call16Async sends a call to registered Tarantool function and returns Future.
364364
// It uses request code for Tarantool 1.6, so future's result is always array of arrays.
365365
// Deprecated since Tarantool 1.7.2.
366366
func (conn *Connection) Call16Async(functionName string, args interface{}) *Future {
367367
req := NewCall16Request(functionName).Args(args)
368-
return conn.DoAsync(req)
368+
return conn.Do(req)
369369
}
370370

371371
// Call17Async sends a call to registered Tarantool function and returns Future.
372372
// It uses request code for Tarantool >= 1.7, so future's result will not be converted
373373
// (though, keep in mind, result is always array)
374374
func (conn *Connection) Call17Async(functionName string, args interface{}) *Future {
375375
req := NewCall17Request(functionName).Args(args)
376-
return conn.DoAsync(req)
376+
return conn.Do(req)
377377
}
378378

379379
// EvalAsync sends a Lua expression for evaluation and returns Future.
380380
func (conn *Connection) EvalAsync(expr string, args interface{}) *Future {
381381
req := NewEvalRequest(expr).Args(args)
382-
return conn.DoAsync(req)
382+
return conn.Do(req)
383383
}
384384

385385
// ExecuteAsync sends a sql expression for execution and returns Future.
386386
// Since 1.6.0
387387
func (conn *Connection) ExecuteAsync(expr string, args interface{}) *Future {
388388
req := NewExecuteRequest(expr).Args(args)
389-
return conn.DoAsync(req)
389+
return conn.Do(req)
390390
}
391391

392392
// KeyValueBind is a type for encoding named SQL parameters

0 commit comments

Comments
 (0)