Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions examples/axum/Cargo.lock

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

4 changes: 2 additions & 2 deletions examples/axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ release = false
crate-type = ["cdylib"]

[dependencies]
worker = { version = "0.7", features = ['http', 'axum'] }
worker-macros = { version = "0.7", features = ['http'] }
worker = { path = "../../worker", features = ['http', 'axum'] }
worker-macros = { path = "../../worker-macros", features = ['http'] }
axum = { version = "0.8", default-features = false, features = ['json'] }
axum-macros = "0.5.0"
tower-service = "0.3.3"
Expand Down
9 changes: 0 additions & 9 deletions examples/axum/src/resources/foos/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ use axum::Json;
use axum_macros::debug_handler;
use worker::Result;

/// `get()` requires the `#[worker::send]` macro because Cloudflare Workers
/// execute a handler's future on a single JavaScript event loop.
///
/// The macro helps make `await` boundaries in the handler's function body `Send`
/// so the worker runtime can safely poll them.
///
/// You can read more about it here in the "`Send` Helpers" section:
/// https://docs.rs/worker/latest/worker/
#[worker::send]
#[debug_handler]
pub async fn get(
State(state): State<AppState>,
Expand Down
8 changes: 3 additions & 5 deletions examples/rpc-client/src/calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@ mod sys {
pub trait Calculator {
async fn add(&self, a: u32, b: u32) -> ::worker::Result<u64>;
}
pub struct CalculatorService(::worker::send::SendWrapper<sys::CalculatorSys>);
pub struct CalculatorService(sys::CalculatorSys);
#[async_trait::async_trait]
impl Calculator for CalculatorService {
async fn add(&self, a: u32, b: u32) -> ::worker::Result<u32> {
let promise = self.0.add(a, b)?;
let fut = ::worker::send::SendFuture::new(
::worker::wasm_bindgen_futures::JsFuture::from(promise),
);
let fut = ::worker::wasm_bindgen_futures::JsFuture::from(promise);
let output = fut.await?;
Ok(::serde_wasm_bindgen::from_value(output)?)
}
}
impl From<::worker::Fetcher> for CalculatorService {
fn from(fetcher: ::worker::Fetcher) -> Self {
Self(::worker::send::SendWrapper::new(fetcher.into_rpc()))
Self(fetcher.into_rpc())
}
}
1 change: 0 additions & 1 deletion test/src/alarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ impl DurableObject for AlarmObject {
}
}

#[worker::send]
pub async fn handle_alarm(_req: Request, env: Env, _data: SomeSharedData) -> Result<Response> {
let namespace = env.durable_object("ALARM")?;
let stub = namespace.id_from_name("alarm")?.get_stub()?;
Expand Down
3 changes: 1 addition & 2 deletions test/src/analytics_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::SomeSharedData;
use uuid::Uuid;
use worker::{AnalyticsEngineDataPointBuilder, Env, Request, Response, Result};

#[worker::send]
pub async fn handle_analytics_event(
req: Request,
env: Env,
Expand Down Expand Up @@ -31,5 +30,5 @@ pub async fn handle_analytics_event(
.add_double(200)
.write_to(&dataset)?;

return Response::ok("Events sent");
Response::ok("Events sent")
}
1 change: 0 additions & 1 deletion test/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub async fn handle_asset(
}

#[cfg(feature = "http")]
#[worker::send]
pub async fn handle_asset(
req: worker::Request,
env: worker::Env,
Expand Down
1 change: 0 additions & 1 deletion test/src/auto_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ impl DurableObject for AutoResponseObject {
}

// Route handler to exercise the Durable Object from tests.
#[worker::send]
pub async fn handle_auto_response(
_req: Request,
env: Env,
Expand Down
22 changes: 15 additions & 7 deletions test/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn key(req: &Request) -> Result<Option<String>> {
Ok(segments.nth(2).map(ToOwned::to_owned))
}

#[worker::send]
pub async fn handle_cache_example(
req: Request,
_env: Env,
Expand All @@ -36,7 +35,6 @@ pub async fn handle_cache_example(
}
}

#[worker::send]
pub async fn handle_cache_api_get(
req: Request,
_env: Env,
Expand All @@ -52,7 +50,6 @@ pub async fn handle_cache_api_get(
Response::error("key missing", 400)
}

#[worker::send]
pub async fn handle_cache_api_put(
req: Request,
_env: Env,
Expand All @@ -71,7 +68,6 @@ pub async fn handle_cache_api_put(
Response::error("key missing", 400)
}

#[worker::send]
pub async fn handle_cache_api_delete(
req: Request,
_env: Env,
Expand All @@ -86,7 +82,6 @@ pub async fn handle_cache_api_delete(
Response::error("key missing", 400)
}

#[worker::send]
pub async fn handle_cache_stream(
req: Request,
_env: Env,
Expand All @@ -100,8 +95,10 @@ pub async fn handle_cache_stream(
Ok(resp)
} else {
console_log!("Cache MISS!");
let mut rng = rand::rng();
let count = rng.random_range(0..10);
let count = {
let mut rng = rand::rng();
rng.random_range(0..10)
};
let stream = futures_util::stream::repeat("Hello, world!\n")
.take(count)
.then(|text| async move {
Expand All @@ -119,3 +116,14 @@ pub async fn handle_cache_stream(
Ok(resp)
}
}

// Compile-time assertion: public async Cache methods return Send futures.
#[allow(dead_code, unused)]
fn _assert_send() {
fn require_send<T: Send>(_t: T) {}
fn cache(c: worker::Cache) {
require_send(c.put("k", worker::Response::empty().unwrap()));
require_send(c.get("k", false));
require_send(c.delete("k", false));
}
}
11 changes: 10 additions & 1 deletion test/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ impl DurableObject for EchoContainer {

const CONTAINER_NAME: &str = "my-container";

#[worker::send]
pub async fn handle_container(
mut req: Request,
env: Env,
Expand Down Expand Up @@ -142,3 +141,13 @@ async fn redir_websocket(dst: WebSocket, src: WebSocket) {
}
}
}

// Compile-time assertion: public async Container methods return Send futures.
#[allow(dead_code, unused)]
fn _assert_send() {
fn require_send<T: Send>(_t: T) {}
fn container(c: worker::Container) {
require_send(c.wait_for_exit());
require_send(c.destroy(None));
}
}
2 changes: 0 additions & 2 deletions test/src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ impl DurableObject for Counter {
}
}

#[worker::send]
pub async fn handle_id(req: Request, env: Env, _data: SomeSharedData) -> Result<Response> {
let durable_object_name = if req.path().contains("shared") {
"SHARED_COUNTER"
Expand All @@ -110,7 +109,6 @@ pub async fn handle_id(req: Request, env: Env, _data: SomeSharedData) -> Result<
stub.fetch_with_str("https://fake-host/").await
}

#[worker::send]
pub async fn handle_websocket(req: Request, env: Env, _data: SomeSharedData) -> Result<Response> {
let durable_object_name = if req.path().contains("shared") {
"SHARED_COUNTER"
Expand Down
Loading
Loading