Ensure functions can be run asynchronously
This commit is contained in:
parent
3b5966144c
commit
f8848e36f5
4 changed files with 56 additions and 28 deletions
|
@ -12,7 +12,6 @@ pub enum Args {
|
||||||
NoneTwo,
|
NoneTwo,
|
||||||
NoneOneTwo,
|
NoneOneTwo,
|
||||||
OneTwo,
|
OneTwo,
|
||||||
OneTwoThree,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check(
|
pub fn check(
|
||||||
|
@ -79,13 +78,6 @@ pub fn check(
|
||||||
message: String::from("The function expects 1 or 2 arguments."),
|
message: String::from("The function expects 1 or 2 arguments."),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Args::OneTwoThree => match args.len() {
|
|
||||||
1 | 2 | 3 => func(ctx, args),
|
|
||||||
_ => Err(Error::ArgumentsError {
|
|
||||||
name: name.to_owned(),
|
|
||||||
message: String::from("The function expects 1, 2, or 3 arguments."),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
Args::Any => func(ctx, args),
|
Args::Any => func(ctx, args),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,26 +2,62 @@ use crate::dbs::Runtime;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
|
|
||||||
pub fn head(_ctx: &Runtime, _args: Vec<Value>) -> Result<Value, Error> {
|
pub async fn head(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
|
||||||
todo!()
|
match args.len() {
|
||||||
|
1 | 2 => todo!(),
|
||||||
|
_ => Err(Error::ArgumentsError {
|
||||||
|
name: String::from("http::head"),
|
||||||
|
message: String::from("The function expects 1 or 2 arguments."),
|
||||||
|
}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(_ctx: &Runtime, _args: Vec<Value>) -> Result<Value, Error> {
|
pub async fn get(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
|
||||||
todo!()
|
match args.len() {
|
||||||
|
1 | 2 => todo!(),
|
||||||
|
_ => Err(Error::ArgumentsError {
|
||||||
|
name: String::from("http::get"),
|
||||||
|
message: String::from("The function expects 1 or 2 arguments."),
|
||||||
|
}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn put(_ctx: &Runtime, _args: Vec<Value>) -> Result<Value, Error> {
|
pub async fn put(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
|
||||||
todo!()
|
match args.len() {
|
||||||
|
1 | 2 | 3 => todo!(),
|
||||||
|
_ => Err(Error::ArgumentsError {
|
||||||
|
name: String::from("http::put"),
|
||||||
|
message: String::from("The function expects 1, 2, or 3 arguments."),
|
||||||
|
}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn post(_ctx: &Runtime, _args: Vec<Value>) -> Result<Value, Error> {
|
pub async fn post(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
|
||||||
todo!()
|
match args.len() {
|
||||||
|
1 | 2 | 3 => todo!(),
|
||||||
|
_ => Err(Error::ArgumentsError {
|
||||||
|
name: String::from("http::post"),
|
||||||
|
message: String::from("The function expects 1, 2, or 3 arguments."),
|
||||||
|
}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn patch(_ctx: &Runtime, _args: Vec<Value>) -> Result<Value, Error> {
|
pub async fn patch(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
|
||||||
todo!()
|
match args.len() {
|
||||||
|
1 | 2 | 3 => todo!(),
|
||||||
|
_ => Err(Error::ArgumentsError {
|
||||||
|
name: String::from("http::patch"),
|
||||||
|
message: String::from("The function expects 1, 2, or 3 arguments."),
|
||||||
|
}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(_ctx: &Runtime, _args: Vec<Value>) -> Result<Value, Error> {
|
pub async fn delete(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
|
||||||
todo!()
|
match args.len() {
|
||||||
|
1 | 2 => todo!(),
|
||||||
|
_ => Err(Error::ArgumentsError {
|
||||||
|
name: String::from("http::delete"),
|
||||||
|
message: String::from("The function expects 1 or 2 arguments."),
|
||||||
|
}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub mod time;
|
||||||
pub mod r#type;
|
pub mod r#type;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
pub fn run(ctx: &Runtime, name: &String, args: Vec<Value>) -> Result<Value, Error> {
|
pub async fn run(ctx: &Runtime, name: &String, args: Vec<Value>) -> Result<Value, Error> {
|
||||||
match name.as_ref() {
|
match name.as_ref() {
|
||||||
//
|
//
|
||||||
"array::combine" => args::check(ctx, name, args, Args::Two, array::combine),
|
"array::combine" => args::check(ctx, name, args, Args::Two, array::combine),
|
||||||
|
@ -55,12 +55,12 @@ pub fn run(ctx: &Runtime, name: &String, args: Vec<Value>) -> Result<Value, Erro
|
||||||
"geo::hash::decode" => args::check(ctx, name, args, Args::One, geo::hash::decode),
|
"geo::hash::decode" => args::check(ctx, name, args, Args::One, geo::hash::decode),
|
||||||
"geo::hash::encode" => args::check(ctx, name, args, Args::OneTwo, geo::hash::encode),
|
"geo::hash::encode" => args::check(ctx, name, args, Args::OneTwo, geo::hash::encode),
|
||||||
//
|
//
|
||||||
"http::head" => args::check(ctx, name, args, Args::OneTwo, http::head),
|
"http::head" => http::head(ctx, args).await,
|
||||||
"http::get" => args::check(ctx, name, args, Args::OneTwo, http::get),
|
"http::get" => http::get(ctx, args).await,
|
||||||
"http::put" => args::check(ctx, name, args, Args::OneTwoThree, http::put),
|
"http::put" => http::put(ctx, args).await,
|
||||||
"http::post" => args::check(ctx, name, args, Args::OneTwoThree, http::post),
|
"http::post" => http::post(ctx, args).await,
|
||||||
"http::patch" => args::check(ctx, name, args, Args::OneTwoThree, http::patch),
|
"http::patch" => http::patch(ctx, args).await,
|
||||||
"http::delete" => args::check(ctx, name, args, Args::OneTwo, http::delete),
|
"http::delete" => http::delete(ctx, args).await,
|
||||||
//
|
//
|
||||||
"is::alphanum" => args::check(ctx, name, args, Args::One, is::alphanum),
|
"is::alphanum" => args::check(ctx, name, args, Args::One, is::alphanum),
|
||||||
"is::alpha" => args::check(ctx, name, args, Args::One, is::alpha),
|
"is::alpha" => args::check(ctx, name, args, Args::One, is::alpha),
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl Function {
|
||||||
let v = v.compute(ctx, opt, exe, doc).await?;
|
let v = v.compute(ctx, opt, exe, doc).await?;
|
||||||
a.push(v);
|
a.push(v);
|
||||||
}
|
}
|
||||||
fnc::run(ctx, s, a)
|
fnc::run(ctx, s, a).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue