use blocks instead of lambdas

This commit is contained in:
Jaroslaw Konik 2025-05-15 07:00:00 +02:00
parent bd4b377fc6
commit 62fcdab69a
3 changed files with 11 additions and 7 deletions

View file

@ -1,5 +1,5 @@
def test_func
rust_func.and_then lambda { |x|
rust_func.and_then do |x|
print('abc' + 5)
}
end
end

View file

@ -3,7 +3,7 @@ $state = {
}
def test_func
rust_func.and_then lambda { |x|
rust_func.and_then do |x|
$state['x'] = x
}
end
end

View file

@ -127,9 +127,13 @@ unsafe impl TypedData for Promise<(), RubyValue> {
}
}
fn then(r_self: magnus::Value, callback: magnus::Value) -> magnus::Value {
fn then(r_self: magnus::Value) -> magnus::Value {
let promise: &Promise<(), RubyValue> = TryConvert::try_convert(r_self).unwrap();
promise.clone().then(RubyValue::new(callback)).into_value()
let ruby = Ruby::get().unwrap();
promise
.clone()
.then(RubyValue::new(ruby.block_proc().unwrap().as_value()))
.into_value()
}
impl Default for RubyRuntime {
@ -147,7 +151,7 @@ impl Default for RubyRuntime {
// TODO: maybe put promise in a module , maybe do so for other runtimes too
let promise = ruby.define_class("Promise", ruby.class_object()).unwrap();
promise
.define_method("and_then", magnus::method!(then, 1))
.define_method("and_then", magnus::method!(then, 0))
.unwrap();
}));
// TODO: add test for those types for every runtime