use blocks instead of lambdas
This commit is contained in:
parent
bd4b377fc6
commit
62fcdab69a
3 changed files with 11 additions and 7 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
def test_func
|
def test_func
|
||||||
rust_func.and_then lambda { |x|
|
rust_func.and_then do |x|
|
||||||
print('abc' + 5)
|
print('abc' + 5)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ $state = {
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_func
|
def test_func
|
||||||
rust_func.and_then lambda { |x|
|
rust_func.and_then do |x|
|
||||||
$state['x'] = x
|
$state['x'] = x
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -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();
|
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 {
|
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
|
// TODO: maybe put promise in a module , maybe do so for other runtimes too
|
||||||
let promise = ruby.define_class("Promise", ruby.class_object()).unwrap();
|
let promise = ruby.define_class("Promise", ruby.class_object()).unwrap();
|
||||||
promise
|
promise
|
||||||
.define_method("and_then", magnus::method!(then, 1))
|
.define_method("and_then", magnus::method!(then, 0))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}));
|
}));
|
||||||
// TODO: add test for those types for every runtime
|
// TODO: add test for those types for every runtime
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue