mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
refactor: rewrite BC, cache exts to op2 (#20486)
Co-authored-by: Matt Mastracci <matthew@mastracci.com>
This commit is contained in:
parent
2a1781afcb
commit
d77f3fba03
2 changed files with 27 additions and 22 deletions
|
@ -11,7 +11,7 @@ use std::rc::Rc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::op;
|
use deno_core::op2;
|
||||||
use deno_core::JsBuffer;
|
use deno_core::JsBuffer;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use deno_core::Resource;
|
use deno_core::Resource;
|
||||||
|
@ -42,7 +42,8 @@ pub type Message = (String, Vec<u8>);
|
||||||
|
|
||||||
struct Unstable(bool); // --unstable
|
struct Unstable(bool); // --unstable
|
||||||
|
|
||||||
#[op]
|
#[op2(fast)]
|
||||||
|
#[smi]
|
||||||
pub fn op_broadcast_subscribe<BC>(
|
pub fn op_broadcast_subscribe<BC>(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
) -> Result<ResourceId, AnyError>
|
) -> Result<ResourceId, AnyError>
|
||||||
|
@ -63,10 +64,10 @@ where
|
||||||
Ok(state.resource_table.add(resource))
|
Ok(state.resource_table.add(resource))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op2(fast)]
|
||||||
pub fn op_broadcast_unsubscribe<BC>(
|
pub fn op_broadcast_unsubscribe<BC>(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
rid: ResourceId,
|
#[smi] rid: ResourceId,
|
||||||
) -> Result<(), AnyError>
|
) -> Result<(), AnyError>
|
||||||
where
|
where
|
||||||
BC: BroadcastChannel + 'static,
|
BC: BroadcastChannel + 'static,
|
||||||
|
@ -76,12 +77,12 @@ where
|
||||||
bc.unsubscribe(&resource)
|
bc.unsubscribe(&resource)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op2(async)]
|
||||||
pub async fn op_broadcast_send<BC>(
|
pub async fn op_broadcast_send<BC>(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
rid: ResourceId,
|
#[smi] rid: ResourceId,
|
||||||
name: String,
|
#[string] name: String,
|
||||||
buf: JsBuffer,
|
#[buffer] buf: JsBuffer,
|
||||||
) -> Result<(), AnyError>
|
) -> Result<(), AnyError>
|
||||||
where
|
where
|
||||||
BC: BroadcastChannel + 'static,
|
BC: BroadcastChannel + 'static,
|
||||||
|
@ -91,10 +92,11 @@ where
|
||||||
bc.send(&resource, name, buf.to_vec()).await
|
bc.send(&resource, name, buf.to_vec()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op2(async)]
|
||||||
|
#[serde]
|
||||||
pub async fn op_broadcast_recv<BC>(
|
pub async fn op_broadcast_recv<BC>(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
rid: ResourceId,
|
#[smi] rid: ResourceId,
|
||||||
) -> Result<Option<Message>, AnyError>
|
) -> Result<Option<Message>, AnyError>
|
||||||
where
|
where
|
||||||
BC: BroadcastChannel + 'static,
|
BC: BroadcastChannel + 'static,
|
||||||
|
|
27
ext/cache/lib.rs
vendored
27
ext/cache/lib.rs
vendored
|
@ -8,6 +8,7 @@ use std::sync::Arc;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::op;
|
use deno_core::op;
|
||||||
|
use deno_core::op2;
|
||||||
use deno_core::serde::Deserialize;
|
use deno_core::serde::Deserialize;
|
||||||
use deno_core::serde::Serialize;
|
use deno_core::serde::Serialize;
|
||||||
use deno_core::ByteString;
|
use deno_core::ByteString;
|
||||||
|
@ -129,10 +130,10 @@ where
|
||||||
cache.storage_open(cache_name).await
|
cache.storage_open(cache_name).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op2(async)]
|
||||||
pub async fn op_cache_storage_has<CA>(
|
pub async fn op_cache_storage_has<CA>(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
cache_name: String,
|
#[string] cache_name: String,
|
||||||
) -> Result<bool, AnyError>
|
) -> Result<bool, AnyError>
|
||||||
where
|
where
|
||||||
CA: Cache,
|
CA: Cache,
|
||||||
|
@ -141,10 +142,10 @@ where
|
||||||
cache.storage_has(cache_name).await
|
cache.storage_has(cache_name).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op2(async)]
|
||||||
pub async fn op_cache_storage_delete<CA>(
|
pub async fn op_cache_storage_delete<CA>(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
cache_name: String,
|
#[string] cache_name: String,
|
||||||
) -> Result<bool, AnyError>
|
) -> Result<bool, AnyError>
|
||||||
where
|
where
|
||||||
CA: Cache,
|
CA: Cache,
|
||||||
|
@ -153,10 +154,11 @@ where
|
||||||
cache.storage_delete(cache_name).await
|
cache.storage_delete(cache_name).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op2(async)]
|
||||||
|
#[smi]
|
||||||
pub async fn op_cache_put<CA>(
|
pub async fn op_cache_put<CA>(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
request_response: CachePutRequest,
|
#[serde] request_response: CachePutRequest,
|
||||||
) -> Result<Option<ResourceId>, AnyError>
|
) -> Result<Option<ResourceId>, AnyError>
|
||||||
where
|
where
|
||||||
CA: Cache,
|
CA: Cache,
|
||||||
|
@ -171,10 +173,10 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op2(async)]
|
||||||
pub async fn op_cache_put_finish<CA>(
|
pub async fn op_cache_put_finish<CA>(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
rid: ResourceId,
|
#[smi] rid: ResourceId,
|
||||||
) -> Result<(), AnyError>
|
) -> Result<(), AnyError>
|
||||||
where
|
where
|
||||||
CA: Cache,
|
CA: Cache,
|
||||||
|
@ -187,10 +189,11 @@ where
|
||||||
cache.put_finish(resource).await
|
cache.put_finish(resource).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op2(async)]
|
||||||
|
#[serde]
|
||||||
pub async fn op_cache_match<CA>(
|
pub async fn op_cache_match<CA>(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
request: CacheMatchRequest,
|
#[serde] request: CacheMatchRequest,
|
||||||
) -> Result<Option<CacheMatchResponse>, AnyError>
|
) -> Result<Option<CacheMatchResponse>, AnyError>
|
||||||
where
|
where
|
||||||
CA: Cache,
|
CA: Cache,
|
||||||
|
@ -206,10 +209,10 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op2(async)]
|
||||||
pub async fn op_cache_delete<CA>(
|
pub async fn op_cache_delete<CA>(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
request: CacheDeleteRequest,
|
#[serde] request: CacheDeleteRequest,
|
||||||
) -> Result<bool, AnyError>
|
) -> Result<bool, AnyError>
|
||||||
where
|
where
|
||||||
CA: Cache,
|
CA: Cache,
|
||||||
|
|
Loading…
Add table
Reference in a new issue