2021-01-12 02:13:41 +09:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
2019-08-14 17:03:02 +02:00
|
|
|
|
2019-10-02 00:51:05 +02:00
|
|
|
pub mod errors;
|
2020-01-21 17:50:06 +01:00
|
|
|
pub mod runtime_compiler;
|
2020-09-10 09:57:45 -04:00
|
|
|
|
2020-09-14 18:48:57 +02:00
|
|
|
use deno_core::error::AnyError;
|
2021-04-12 21:55:05 +02:00
|
|
|
use deno_core::op_async;
|
|
|
|
use deno_core::op_sync;
|
2020-09-21 18:36:37 +02:00
|
|
|
use deno_core::serde_json::Value;
|
2020-09-10 09:57:45 -04:00
|
|
|
use deno_core::JsRuntime;
|
|
|
|
use deno_core::OpState;
|
|
|
|
use deno_core::ZeroCopyBuf;
|
2020-12-13 19:45:53 +01:00
|
|
|
use deno_runtime::metrics::metrics_op;
|
2020-09-10 09:57:45 -04:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::future::Future;
|
|
|
|
use std::rc::Rc;
|
|
|
|
|
2021-04-12 21:55:05 +02:00
|
|
|
pub fn reg_async<F, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F)
|
2020-09-10 09:57:45 -04:00
|
|
|
where
|
2021-04-02 15:47:57 +02:00
|
|
|
F: Fn(Rc<RefCell<OpState>>, Value, Option<ZeroCopyBuf>) -> R + 'static,
|
2020-09-14 18:48:57 +02:00
|
|
|
R: Future<Output = Result<Value, AnyError>> + 'static,
|
2020-09-10 09:57:45 -04:00
|
|
|
{
|
2021-04-12 21:55:05 +02:00
|
|
|
rt.register_op(name, metrics_op(name, op_async(op_fn)));
|
2020-09-10 09:57:45 -04:00
|
|
|
}
|
|
|
|
|
2021-04-12 21:55:05 +02:00
|
|
|
pub fn reg_sync<F>(rt: &mut JsRuntime, name: &'static str, op_fn: F)
|
2020-09-10 09:57:45 -04:00
|
|
|
where
|
2021-04-02 15:47:57 +02:00
|
|
|
F: Fn(&mut OpState, Value, Option<ZeroCopyBuf>) -> Result<Value, AnyError>
|
2020-09-10 09:57:45 -04:00
|
|
|
+ 'static,
|
|
|
|
{
|
2021-04-12 21:55:05 +02:00
|
|
|
rt.register_op(name, metrics_op(name, op_sync(op_fn)));
|
2020-09-10 09:57:45 -04:00
|
|
|
}
|