@@ -998,6 +998,90 @@ func ExampleBeginRequest_TxnIsolation() {
998998 fmt .Printf ("Select after Rollback: response is %#v\n " , data )
999999}
10001000
1001+ func ExampleBeginRequest_IsSync () {
1002+ conn := exampleConnect (dialer , opts )
1003+ defer conn .Close ()
1004+
1005+ // Tarantool supports IS_SYNC flag for BeginRequest since version 3.1.0.
1006+ isLess , err := test_helpers .IsTarantoolVersionLess (3 , 1 , 0 )
1007+ if err != nil || isLess {
1008+ return
1009+ }
1010+
1011+ stream , err := conn .NewStream ()
1012+ if err != nil {
1013+ fmt .Printf ("error getting the stream: %s\n " , err )
1014+ return
1015+ }
1016+
1017+ // Begin transaction with synchronous mode.
1018+ req := tarantool .NewBeginRequest ().IsSync (true )
1019+ resp , err := stream .Do (req ).GetResponse ()
1020+ switch {
1021+ case err != nil :
1022+ fmt .Printf ("error getting the response: %s\n " , err )
1023+ case resp .Header ().Error != tarantool .ErrorNo :
1024+ fmt .Printf ("response error code: %s\n " , resp .Header ().Error )
1025+ default :
1026+ fmt .Println ("Success." )
1027+ }
1028+ }
1029+
1030+ func ExampleCommitRequest_IsSync () {
1031+ conn := exampleConnect (dialer , opts )
1032+ defer conn .Close ()
1033+
1034+ // Tarantool supports IS_SYNC flag for CommitRequest since version 3.1.0.
1035+ isLess , err := test_helpers .IsTarantoolVersionLess (3 , 1 , 0 )
1036+ if err != nil || isLess {
1037+ return
1038+ }
1039+
1040+ var req tarantool.Request
1041+
1042+ stream , err := conn .NewStream ()
1043+ if err != nil {
1044+ fmt .Printf ("error getting the stream: %s\n " , err )
1045+ return
1046+ }
1047+
1048+ // Begin transaction.
1049+ req = tarantool .NewBeginRequest ()
1050+ resp , err := stream .Do (req ).GetResponse ()
1051+ switch {
1052+ case err != nil :
1053+ fmt .Printf ("error getting the response: %s\n " , err )
1054+ return
1055+ case resp .Header ().Error != tarantool .ErrorNo :
1056+ fmt .Printf ("response error code: %s\n " , resp .Header ().Error )
1057+ return
1058+ }
1059+
1060+ // Insert in stream.
1061+ req = tarantool .NewReplaceRequest ("test" ).Tuple ([]interface {}{1 , "test" })
1062+ resp , err = stream .Do (req ).GetResponse ()
1063+ switch {
1064+ case err != nil :
1065+ fmt .Printf ("error getting the response: %s\n " , err )
1066+ return
1067+ case resp .Header ().Error != tarantool .ErrorNo :
1068+ fmt .Printf ("response error code: %s\n " , resp .Header ().Error )
1069+ return
1070+ }
1071+
1072+ // Commit transaction in sync mode.
1073+ req = tarantool .NewCommitRequest ().IsSync (true )
1074+ resp , err = stream .Do (req ).GetResponse ()
1075+ switch {
1076+ case err != nil :
1077+ fmt .Printf ("error getting the response: %s\n " , err )
1078+ case resp .Header ().Error != tarantool .ErrorNo :
1079+ fmt .Printf ("response error code: %s\n " , resp .Header ().Error )
1080+ default :
1081+ fmt .Println ("Success." )
1082+ }
1083+ }
1084+
10011085func ExampleErrorNo () {
10021086 conn := exampleConnect (dialer , opts )
10031087 defer conn .Close ()
0 commit comments