network debugging
This commit is contained in:
@@ -51,36 +51,36 @@ impl DartIsolateWrapper {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn result<T: IntoDart, E: Serialize>(&self, result: Result<T, E>) -> bool {
|
||||
pub fn result<T: IntoDart, E: Serialize>(self, result: Result<T, E>) -> bool {
|
||||
match result {
|
||||
Ok(v) => self.ok(v),
|
||||
Err(e) => self.err_json(e),
|
||||
}
|
||||
}
|
||||
pub fn result_json<T: Serialize, E: Serialize>(&self, result: Result<T, E>) -> bool {
|
||||
pub fn result_json<T: Serialize, E: Serialize>(self, result: Result<T, E>) -> bool {
|
||||
match result {
|
||||
Ok(v) => self.ok_json(v),
|
||||
Err(e) => self.err_json(e),
|
||||
}
|
||||
}
|
||||
pub fn ok<T: IntoDart>(&self, value: T) -> bool {
|
||||
pub fn ok<T: IntoDart>(self, value: T) -> bool {
|
||||
self.isolate
|
||||
.post(vec![MESSAGE_OK.into_dart(), value.into_dart()])
|
||||
}
|
||||
|
||||
pub fn ok_json<T: Serialize>(&self, value: T) -> bool {
|
||||
pub fn ok_json<T: Serialize>(self, value: T) -> bool {
|
||||
self.isolate.post(vec![
|
||||
MESSAGE_OK_JSON.into_dart(),
|
||||
serialize_json(value).into_dart(),
|
||||
])
|
||||
}
|
||||
|
||||
// pub fn err<E: IntoDart>(&self, error: E) -> bool {
|
||||
// pub fn err<E: IntoDart>(self, error: E) -> bool {
|
||||
// self.isolate
|
||||
// .post(vec![MESSAGE_ERR.into_dart(), error.into_dart()])
|
||||
// }
|
||||
|
||||
pub fn err_json<E: Serialize>(&self, error: E) -> bool {
|
||||
pub fn err_json<E: Serialize>(self, error: E) -> bool {
|
||||
self.isolate.post(vec![
|
||||
MESSAGE_ERR_JSON.into_dart(),
|
||||
serialize_json(error).into_dart(),
|
||||
@@ -88,21 +88,35 @@ impl DartIsolateWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
struct DartIsolateStreamInner {
|
||||
pub isolate: Option<Isolate>,
|
||||
}
|
||||
|
||||
impl Drop for DartIsolateStreamInner {
|
||||
fn drop(&mut self) {
|
||||
if let Some(isolate) = self.isolate {
|
||||
isolate.post(vec![MESSAGE_STREAM_CLOSE.into_dart()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DartIsolateStream {
|
||||
isolate: Arc<Mutex<Option<Isolate>>>,
|
||||
inner: Arc<Mutex<DartIsolateStreamInner>>,
|
||||
}
|
||||
|
||||
impl DartIsolateStream {
|
||||
pub fn new(port: i64) -> Self {
|
||||
DartIsolateStream {
|
||||
isolate: Arc::new(Mutex::new(Some(Isolate::new(port)))),
|
||||
inner: Arc::new(Mutex::new(DartIsolateStreamInner {
|
||||
isolate: Some(Isolate::new(port)),
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn item<T: IntoDart>(&self, value: T) -> bool {
|
||||
// let isolate = self.isolate.lock();
|
||||
// if let Some(isolate) = &*isolate {
|
||||
// let mut inner = self.inner.lock();
|
||||
// if let Some(isolate) = inner.isolate.take() {
|
||||
// isolate.post(vec![MESSAGE_STREAM_ITEM.into_dart(), value.into_dart()])
|
||||
// } else {
|
||||
// false
|
||||
@@ -110,8 +124,8 @@ impl DartIsolateStream {
|
||||
// }
|
||||
|
||||
pub fn item_json<T: Serialize>(&self, value: T) -> bool {
|
||||
let isolate = self.isolate.lock();
|
||||
if let Some(isolate) = &*isolate {
|
||||
let inner = self.inner.lock();
|
||||
if let Some(isolate) = &inner.isolate {
|
||||
isolate.post(vec![
|
||||
MESSAGE_STREAM_ITEM_JSON.into_dart(),
|
||||
serialize_json(value).into_dart(),
|
||||
@@ -122,8 +136,8 @@ impl DartIsolateStream {
|
||||
}
|
||||
|
||||
// pub fn abort<E: IntoDart>(self, error: E) -> bool {
|
||||
// let mut isolate = self.isolate.lock();
|
||||
// if let Some(isolate) = isolate.take() {
|
||||
// let mut inner = self.inner.lock();
|
||||
// if let Some(isolate) = inner.isolate.take() {
|
||||
// isolate.post(vec![MESSAGE_STREAM_ABORT.into_dart(), error.into_dart()])
|
||||
// } else {
|
||||
// false
|
||||
@@ -131,8 +145,8 @@ impl DartIsolateStream {
|
||||
// }
|
||||
|
||||
pub fn abort_json<E: Serialize>(self, error: E) -> bool {
|
||||
let mut isolate = self.isolate.lock();
|
||||
if let Some(isolate) = isolate.take() {
|
||||
let mut inner = self.inner.lock();
|
||||
if let Some(isolate) = inner.isolate.take() {
|
||||
isolate.post(vec![
|
||||
MESSAGE_STREAM_ABORT_JSON.into_dart(),
|
||||
serialize_json(error).into_dart(),
|
||||
@@ -143,20 +157,11 @@ impl DartIsolateStream {
|
||||
}
|
||||
|
||||
pub fn close(self) -> bool {
|
||||
let mut isolate = self.isolate.lock();
|
||||
if let Some(isolate) = isolate.take() {
|
||||
let mut inner = self.inner.lock();
|
||||
if let Some(isolate) = inner.isolate.take() {
|
||||
isolate.post(vec![MESSAGE_STREAM_CLOSE.into_dart()])
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for DartIsolateStream {
|
||||
fn drop(&mut self) {
|
||||
let mut isolate = self.isolate.lock();
|
||||
if let Some(isolate) = isolate.take() {
|
||||
isolate.post(vec![MESSAGE_STREAM_CLOSE.into_dart()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user