follow JS promise model in cf-worker build

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
ゆめ 2024-11-13 10:49:30 -06:00
parent 146e317849
commit cf1af773a6
No known key found for this signature in database
2 changed files with 13 additions and 10 deletions

View file

@ -540,16 +540,15 @@ pub mod cf_worker {
let abs = abc.signal();
let req = Fetch::Request(req);
let mut resp_fut = std::pin::pin!(req
worker::wasm_bindgen_futures::spawn_local(async move {
worker::Delay::from(Duration::from_secs(5)).await;
abc.abort();
});
let resp = std::pin::pin!(req
.send_with_signal(&abs)
.map_err(ErrorResponse::worker_fetch_error));
let timeout = std::pin::pin!(worker::Delay::from(Duration::from_secs(5)));
let resp = futures::select! {
resp = resp_fut => resp?,
_ = timeout.fuse() => return Err(ErrorResponse::upstream_timeout()),
};
.map_err(ErrorResponse::worker_fetch_error))
.await?;
if resp.status_code() == 301 || resp.status_code() == 302 {
if let Ok(Some(location)) = resp.headers().get("location") {

View file

@ -3,4 +3,8 @@ main = "build/worker/shim.mjs"
compatibility_date = "2024-11-11"
[build]
command = "cargo install -q worker-build && worker-build --release --features cf-worker"
command = "cargo install -q worker-build && worker-build --release --features cf-worker"
[observability]
enabled = true
head_sampling_rate = 1