Class: LWTarantool::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/lwtarantool/request.rb,
ext/lwtarantool/request.c,
ext/lwtarantool/request.c,
ext/lwtarantool/request.c,
ext/lwtarantool/request.c

Overview

Class for work with Tarantool requests

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connLWTarantool::Connection (readonly)

Correspond tarantool connection.

Returns:



13
14
15
# File 'lib/lwtarantool/request.rb', line 13

def conn
  @conn
end

Instance Method Details

#errorString?

Wait for request processing and return tarantool error message.

Examples:

req.error

Returns:

  • (String)

    Tarantool error message if request failed.

  • (nil)

    nil if request success.



53
54
55
56
# File 'lib/lwtarantool/request.rb', line 53

def error
  wait unless ready?
  _error
end

#idInteger

Request id

Returns:

  • (Integer)

    id



51
52
53
54
55
56
57
# File 'ext/lwtarantool/request.c', line 51

static VALUE
lwt_request_id( VALUE self) {
  lwt_request_t * req;
  Data_Get_Struct(self, lwt_request_t, req);

  return rb_uint2inum(req->id);
}

#ready?Boolean

Check if request already processed.

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
73
# File 'ext/lwtarantool/request.c', line 64

static VALUE
lwt_request_is_ready( VALUE self) {
  lwt_request_t * req;
  Data_Get_Struct(self, lwt_request_t, req);

  if (req->reply == NULL) 
    return Qfalse;
  else
    return Qtrue;
}

#resultArray?

Wait for request processing and return tarantool reponse data.

Examples:

req.result

Returns:

  • (Array)

    response data if request was successfull processed.

  • (nil)

    nil if request failed.



38
39
40
41
42
# File 'lib/lwtarantool/request.rb', line 38

def result
  wait unless ready?
  res = _result
  MessagePack.unpack(res) unless res.nil?
end

#waitObject

Wait for request be processed by Tarantool.

Examples:

req.wait

Raises:



25
26
27
# File 'lib/lwtarantool/request.rb', line 25

def wait
  conn.read until ready?
end