Module: Groonga::RequestCanceler

Defined in:
ext/groonga/rb-grn-request-canceler.c,
ext/groonga/rb-grn-request-canceler.c

Overview

This module provides API for canceling requests.

Class Method Summary collapse

Class Method Details

.cancel(request_id) ⇒ Boolean

Cancels the specified request.

Examples:

Cancels a request by ID

request_id = "request-29"
Groonga::RequestCanceler.cancel(request_id)

Returns true if the request is canceled, false otherwise.

Parameters:

  • request_id (String)

    The ID of request to be canceled.

Returns:

  • (Boolean)

    true if the request is canceled, false otherwise.

Since:

  • 6.0.2



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'ext/groonga/rb-grn-request-canceler.c', line 115

static VALUE
rb_grn_request_canceler_s_cancel (VALUE module, VALUE rb_request_id)
{
    const char *request_id;
    unsigned int request_id_size;
    grn_bool canceled;

    request_id = StringValuePtr(rb_request_id);
    request_id_size = RSTRING_LEN(rb_request_id);
    canceled = grn_request_canceler_cancel(request_id, request_id_size);

    return CBOOL2RVAL(canceled);
}

.cancel_allBoolean

Cancels all running requests.

Examples:

Cancels all requests

Groonga::RequestCanceler.cancel_all

Returns true if one or more requests are canceled, false otherwise.

Returns:

  • (Boolean)

    true if one or more requests are canceled, false otherwise.

Since:

  • 6.0.2



141
142
143
144
145
146
147
148
149
# File 'ext/groonga/rb-grn-request-canceler.c', line 141

static VALUE
rb_grn_request_canceler_s_cancel_all (VALUE module)
{
    grn_bool canceled;

    canceled = grn_request_canceler_cancel_all();

    return CBOOL2RVAL(canceled);
}

.register(request_id) ⇒ void

Registers a request. The request can be canceled by cancel.

Examples:

Register a request

request_id = "request-29"
Groonga::RequestCanceler.register(request_id)

This method returns an undefined value.

Parameters:

  • request_id (String)

    The ID of request to be registered.

Since:

  • 6.0.2



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'ext/groonga/rb-grn-request-canceler.c', line 43

static VALUE
rb_grn_request_canceler_s_register (int argc, VALUE *argv, VALUE module)
{
    VALUE rb_request_id;
    VALUE rb_options;
    VALUE rb_context;
    const char *request_id;
    unsigned int request_id_size;
    grn_ctx *context;

    rb_scan_args(argc, argv, "11", &rb_request_id, &rb_options);
    rb_grn_scan_options(rb_options,
                        "context", &rb_context,
                        NULL);
    context = rb_grn_context_ensure(&rb_context);

    request_id = StringValuePtr(rb_request_id);
    request_id_size = RSTRING_LEN(rb_request_id);
    grn_request_canceler_register(context, request_id, request_id_size);

    return Qnil;
}

.unregister(request_id) ⇒ void

Unregisters the specified request.

Examples:

Unregister a request by ID

request_id = "request-29"
Groonga::RequestCanceler.unregister(request_id)

This method returns an undefined value.

Parameters:

  • request_id (String)

    The ID of request to be unregistered.

Since:

  • 6.0.2



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'ext/groonga/rb-grn-request-canceler.c', line 79

static VALUE
rb_grn_request_canceler_s_unregister (int argc, VALUE *argv, VALUE module)
{
    VALUE rb_request_id;
    VALUE rb_options;
    VALUE rb_context;
    const char *request_id;
    unsigned int request_id_size;
    grn_ctx *context;

    rb_scan_args(argc, argv, "11", &rb_request_id, &rb_options);
    rb_grn_scan_options(rb_options,
                        "context", &rb_context,
                        NULL);
    context = rb_grn_context_ensure(&rb_context);

    request_id = StringValuePtr(rb_request_id);
    request_id_size = RSTRING_LEN(rb_request_id);
    grn_request_canceler_unregister(context, request_id, request_id_size);

    return Qnil;
}