Skip to content

Commit

Permalink
Enumerator should use a non-blocking fiber. (#10478)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Apr 7, 2024
1 parent eaa6e4b commit dfa0897
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cont.c
Expand Up @@ -2382,7 +2382,7 @@ rb_fiber_initialize(int argc, VALUE* argv, VALUE self)
VALUE
rb_fiber_new_storage(rb_block_call_func_t func, VALUE obj, VALUE storage)
{
return fiber_initialize(fiber_alloc(rb_cFiber), rb_proc_new(func, obj), rb_fiber_pool_default(Qnil), 1, storage);
return fiber_initialize(fiber_alloc(rb_cFiber), rb_proc_new(func, obj), rb_fiber_pool_default(Qnil), 0, storage);
}

VALUE
Expand Down
1 change: 1 addition & 0 deletions internal/parse.h
Expand Up @@ -68,6 +68,7 @@ rb_parser_string_t *rb_str_to_parser_string(rb_parser_t *p, VALUE str);
void rb_parser_warn_duplicate_keys(struct parser_params *p, NODE *hash);
int rb_parser_dvar_defined_ref(struct parser_params*, ID, ID**);
ID rb_parser_internal_id(struct parser_params*);
VALUE rb_parser_node_case_when_optimizable_literal(struct parser_params *p, const NODE *const node);
int rb_parser_reg_fragment_check(struct parser_params*, rb_parser_string_t*, int);
int rb_reg_named_capture_assign_iter_impl(struct parser_params *p, const char *s, long len, rb_encoding *enc, NODE **succ_block, const rb_code_location_t *loc);
int rb_parser_local_defined(struct parser_params *p, ID id, const struct rb_iseq_struct *iseq);
Expand Down
8 changes: 8 additions & 0 deletions test/fiber/test_enumerator.rb
Expand Up @@ -42,4 +42,12 @@ def test_read_characters
assert_predicate(i, :closed?)
assert_predicate(o, :closed?)
end

def enumerator_fiber_is_nonblocking
enumerator = Enumerator.new do |yielder|
yielder << Fiber.current.blocking?
end

assert_equal(false, enumerator.next)
end
end

0 comments on commit dfa0897

Please sign in to comment.