Skip to content

Commit

Permalink
feat(runtime,serverless,wpt): use once_cell instead of lazy_static (
Browse files Browse the repository at this point in the history
  • Loading branch information
QuiiBz authored Apr 22, 2023
1 parent 5f264ac commit 54df73e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 21 deletions.
7 changes: 7 additions & 0 deletions .changeset/poor-parents-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@lagon/runtime': patch
'@lagon/serverless': patch
'@lagon/wpt-runner': patch
---

Use once_cell instead of lazy_static
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/runtime_isolate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ hyper-tls = { version = "0.5.0", features = ["vendored"] }
flume = "0.10.14"
anyhow = "1.0.70"
log = { version = "0.4.17", features = ["std", "kv_unstable"] }
lazy_static = "1.4.0"
once_cell = "1.17.1"
async-recursion = "1.0.4"
linked-hash-map = "0.5.6"
lagon-runtime-v8-utils = { path = "../runtime_v8_utils" }
Expand Down
8 changes: 3 additions & 5 deletions crates/runtime_isolate/src/bindings/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ use hyper::{
};
use hyper_tls::HttpsConnector;
use lagon_runtime_http::{FromV8, Request, Response};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;

use crate::{bindings::PromiseResult, Isolate};

use super::BindingResult;

lazy_static! {
static ref CLIENT: Client<HttpsConnector<HttpConnector>> =
Client::builder().build::<_, Body>(HttpsConnector::new());
}
static CLIENT: Lazy<Client<HttpsConnector<HttpConnector>>> =
Lazy::new(|| Client::builder().build::<_, Body>(HttpsConnector::new()));

type Arg = Request;

Expand Down
2 changes: 1 addition & 1 deletion crates/serverless/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ serde_json = "1.0"
metrics = "0.21.0"
metrics-exporter-prometheus = { version = "0.12.0", default-features = false, features = ["http-listener"] }
log = { version = "0.4.17", features = ["std", "kv_unstable", "kv_unstable_serde"] }
lazy_static = "1.4.0"
once_cell = "1.17.1"
anyhow = "1.0.70"
tokio-cron-scheduler = "0.9.4"
dashmap = "5.4.0"
Expand Down
7 changes: 3 additions & 4 deletions crates/serverless/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use std::env;

// TODO add back cron jobs
Expand All @@ -7,8 +7,7 @@ pub mod clickhouse;
pub mod deployments;
pub mod serverless;

lazy_static! {
pub static ref REGION: String = env::var("LAGON_REGION").expect("LAGON_REGION must be set");
}
pub static REGION: Lazy<String> =
Lazy::new(|| env::var("LAGON_REGION").expect("LAGON_REGION must be set"));

pub const SNAPSHOT_BLOB: &[u8] = include_bytes!("../snapshot.bin");
2 changes: 1 addition & 1 deletion crates/wpt-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ lagon-runtime-http = { path = "../runtime_http" }
lagon-runtime-isolate = { path = "../runtime_isolate" }
flume = "0.10.14"
colored = "2.0.0"
lazy_static = "1.4.0"
once_cell = "1.17.1"
12 changes: 6 additions & 6 deletions crates/wpt-runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use colored::*;
use lagon_runtime::{options::RuntimeOptions, Runtime};
use lagon_runtime_http::{Request, RunResult};
use lagon_runtime_isolate::{options::IsolateOptions, Isolate, IsolateEvent, IsolateRequest};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use std::{
env, fs,
path::{Path, PathBuf},
Expand Down Expand Up @@ -39,13 +39,13 @@ const SUPPORT_BLOB: &str = include_str!("../../../tools/wpt/FileAPI/support/Blob
const SUPPORT_FORMDATA: &str =
include_str!("../../../tools/wpt/FileAPI/support/send-file-formdata-helper.js");

lazy_static! {
static ref RESULT: Mutex<(usize, usize, usize)> = Mutex::new((0, 0, 0));
static ref TEST_HARNESS: String = include_str!("../../../tools/wpt/resources/testharness.js")
static RESULT: Lazy<Mutex<(usize, usize, usize)>> = Lazy::new(|| Mutex::new((0, 0, 0)));
static TEST_HARNESS: Lazy<String> = Lazy::new(|| {
include_str!("../../../tools/wpt/resources/testharness.js")
.to_owned()
.replace("})(self);", "})(globalThis);")
.replace("debug: false", "debug: true");
}
.replace("debug: false", "debug: true")
});

const SKIP_TESTS: [&str; 16] = [
// request
Expand Down

0 comments on commit 54df73e

Please sign in to comment.