follow JS promise model in cf-worker build
Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
parent
146e317849
commit
cf1af773a6
2 changed files with 13 additions and 10 deletions
|
@ -540,16 +540,15 @@ pub mod cf_worker {
|
||||||
let abs = abc.signal();
|
let abs = abc.signal();
|
||||||
let req = Fetch::Request(req);
|
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)
|
.send_with_signal(&abs)
|
||||||
.map_err(ErrorResponse::worker_fetch_error));
|
.map_err(ErrorResponse::worker_fetch_error))
|
||||||
|
.await?;
|
||||||
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()),
|
|
||||||
};
|
|
||||||
|
|
||||||
if resp.status_code() == 301 || resp.status_code() == 302 {
|
if resp.status_code() == 301 || resp.status_code() == 302 {
|
||||||
if let Ok(Some(location)) = resp.headers().get("location") {
|
if let Ok(Some(location)) = resp.headers().get("location") {
|
||||||
|
|
|
@ -4,3 +4,7 @@ compatibility_date = "2024-11-11"
|
||||||
|
|
||||||
[build]
|
[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
|
||||||
|
|
Loading…
Reference in a new issue