mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
channel: Make pending_requests a field of the Channel type
This is required to send redraw notifications while a msgpack-rpc call is being performed by another channel.
This commit is contained in:
parent
2db4049274
commit
df1f62194e
@ -45,6 +45,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t id;
|
uint64_t id;
|
||||||
|
size_t pending_requests;
|
||||||
PMap(cstr_t) *subscribed_events;
|
PMap(cstr_t) *subscribed_events;
|
||||||
bool is_job, closed;
|
bool is_job, closed;
|
||||||
msgpack_unpacker *unpacker;
|
msgpack_unpacker *unpacker;
|
||||||
@ -83,7 +84,6 @@ static uint64_t next_id = 1;
|
|||||||
static PMap(uint64_t) *channels = NULL;
|
static PMap(uint64_t) *channels = NULL;
|
||||||
static PMap(cstr_t) *event_strings = NULL;
|
static PMap(cstr_t) *event_strings = NULL;
|
||||||
static msgpack_sbuffer out_buffer;
|
static msgpack_sbuffer out_buffer;
|
||||||
static size_t pending_requests = 0;
|
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "msgpack_rpc/channel.c.generated.h"
|
# include "msgpack_rpc/channel.c.generated.h"
|
||||||
@ -193,20 +193,21 @@ bool channel_send_event(uint64_t id, char *name, Array args)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pending_requests) {
|
if (channel) {
|
||||||
DelayedNotification p = {
|
if (channel->pending_requests) {
|
||||||
.channel = channel,
|
DelayedNotification p = {
|
||||||
.method = cstr_to_string(name),
|
.channel = channel,
|
||||||
.args = args
|
.method = cstr_to_string(name),
|
||||||
};
|
.args = args
|
||||||
// Pending request, queue the notification for sending later
|
};
|
||||||
*kl_pushp(DelayedNotification, delayed_notifications) = p;
|
// Pending request, queue the notification for sending later
|
||||||
} else {
|
*kl_pushp(DelayedNotification, delayed_notifications) = p;
|
||||||
if (channel) {
|
|
||||||
send_event(channel, name, args);
|
|
||||||
} else {
|
} else {
|
||||||
broadcast_event(name, args);
|
send_event(channel, name, args);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// TODO(tarruda): Implement event broadcasting in vimscript
|
||||||
|
broadcast_event(name, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -239,10 +240,10 @@ Object channel_send_call(uint64_t id,
|
|||||||
// Push the frame
|
// Push the frame
|
||||||
ChannelCallFrame frame = {request_id, false, false, NIL};
|
ChannelCallFrame frame = {request_id, false, false, NIL};
|
||||||
kv_push(ChannelCallFrame *, channel->call_stack, &frame);
|
kv_push(ChannelCallFrame *, channel->call_stack, &frame);
|
||||||
pending_requests++;
|
channel->pending_requests++;
|
||||||
event_poll_until(-1, frame.returned);
|
event_poll_until(-1, frame.returned);
|
||||||
(void)kv_pop(channel->call_stack);
|
(void)kv_pop(channel->call_stack);
|
||||||
pending_requests--;
|
channel->pending_requests--;
|
||||||
|
|
||||||
if (frame.errored) {
|
if (frame.errored) {
|
||||||
api_set_error(err, Exception, "%s", frame.result.data.string.data);
|
api_set_error(err, Exception, "%s", frame.result.data.string.data);
|
||||||
@ -254,7 +255,7 @@ Object channel_send_call(uint64_t id,
|
|||||||
free_channel(channel);
|
free_channel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pending_requests) {
|
if (!channel->pending_requests) {
|
||||||
send_delayed_notifications();
|
send_delayed_notifications();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -681,6 +682,7 @@ static Channel *register_channel(void)
|
|||||||
rv->closed = false;
|
rv->closed = false;
|
||||||
rv->unpacker = msgpack_unpacker_new(MSGPACK_UNPACKER_INIT_BUFFER_SIZE);
|
rv->unpacker = msgpack_unpacker_new(MSGPACK_UNPACKER_INIT_BUFFER_SIZE);
|
||||||
rv->id = next_id++;
|
rv->id = next_id++;
|
||||||
|
rv->pending_requests = 0;
|
||||||
rv->subscribed_events = pmap_new(cstr_t)();
|
rv->subscribed_events = pmap_new(cstr_t)();
|
||||||
rv->next_request_id = 1;
|
rv->next_request_id = 1;
|
||||||
kv_init(rv->call_stack);
|
kv_init(rv->call_stack);
|
||||||
|
Loading…
Reference in New Issue
Block a user