Skip to content

Commit

Permalink
change sig from &In to In
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop committed May 24, 2024
1 parent 02d77a3 commit 40a2bf5
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/cli/javascript/request_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl RequestFilter {
async fn on_request(&self, mut request: reqwest::Request) -> anyhow::Result<Response<Bytes>> {
let js_request = WorkerRequest::try_from(&request)?;
let event = Event::Request(js_request);
let command = self.worker.call("onRequest", &event).await?;
let command = self.worker.call("onRequest", event).await?;
match command {
Some(command) => match command {
Command::Request(js_request) => {
Expand Down
11 changes: 3 additions & 8 deletions src/cli/javascript/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,9 @@ impl Drop for Runtime {

#[async_trait::async_trait]
impl WorkerIO<Event, Command> for Runtime {
async fn call(
&self,
name: &'async_trait str,
event: &'async_trait Event,
) -> anyhow::Result<Option<Command>> {
async fn call(&self, name: &'async_trait str, event: Event) -> anyhow::Result<Option<Command>> {
let script = self.script.clone();
let name = name.to_string(); // TODO
let event = event.clone(); // TODO
if let Some(runtime) = &self.tokio_runtime {
runtime
.spawn(async move {
Expand All @@ -108,11 +103,11 @@ impl WorkerIO<ConstValue, ConstValue> for Runtime {
async fn call(
&self,
name: &'async_trait str,
input: &'async_trait ConstValue,
input: ConstValue,
) -> anyhow::Result<Option<ConstValue>> {
let script = self.script.clone();
let name = name.to_string();
let value = serde_json::to_string(input)?;
let value = serde_json::to_string(&input)?;
if let Some(runtime) = &self.tokio_runtime {
runtime
.spawn(async move {
Expand Down
2 changes: 1 addition & 1 deletion src/core/lambda/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl IO {
Ok(res.body)
}
IO::Js { name: method } => {
let value = ctx.value().unwrap_or(&ConstValue::Null);
let value = ctx.value().cloned().unwrap_or(ConstValue::Null);
let value = ctx
.request_ctx
.runtime
Expand Down
6 changes: 1 addition & 5 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ pub type EntityCache = dyn Cache<Key = u64, Value = ConstValue>;
#[async_trait::async_trait]
pub trait WorkerIO<In, Out>: Send + Sync + 'static {
/// Calls a global JS function
async fn call(
&self,
name: &'async_trait str,
input: &'async_trait In,
) -> anyhow::Result<Option<Out>>;
async fn call(&self, name: &'async_trait str, input: In) -> anyhow::Result<Option<Out>>;
}

pub fn is_default<T: Default + Eq>(val: &T) -> bool {
Expand Down
10 changes: 2 additions & 8 deletions src/core/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub struct DefaultJsRuntime;

#[async_trait::async_trait]
impl<A: Send + Sync + 'static, B> WorkerIO<A, B> for DefaultJsRuntime {
async fn call(&self, _: &'async_trait str, _: &'async_trait A) -> anyhow::Result<Option<B>> {
async fn call(&self, _: &'async_trait str, _: A) -> anyhow::Result<Option<B>> {
anyhow::bail!("JavaScript runtime is not supported in this build")
}

Check warning on line 9 in src/core/worker.rs

View check run for this annotation

Codecov / codecov/patch

src/core/worker.rs#L7-L9

Added lines #L7 - L9 were not covered by tests
}
Expand All @@ -15,13 +15,7 @@ pub struct WorkerResponse(pub Response<String>);
#[derive(Debug)]
pub struct WorkerRequest(pub reqwest::Request);

impl Clone for WorkerRequest {
fn clone(&self) -> Self {
WorkerRequest(self.0.try_clone().unwrap())
}
}

#[derive(Debug, Clone)]
#[derive(Debug)]
pub enum Event {
Request(WorkerRequest),
}
Expand Down

1 comment on commit 40a2bf5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 6.68ms 3.46ms 158.30ms 77.91%
Req/Sec 3.81k 198.07 4.41k 92.00%

454683 requests in 30.01s, 2.28GB read

Requests/sec: 15148.53

Transfer/sec: 77.75MB

Please sign in to comment.