-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0961e29
commit dfb67f3
Showing
9 changed files
with
151 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::{ | ||
cell::Cell, | ||
future::poll_fn, | ||
task::{Poll, Waker}, | ||
}; | ||
|
||
use crate::Body; | ||
|
||
// TODO: Make this private | ||
pub enum YieldMsg { | ||
YieldBody, | ||
YieldBodyResult(serde_json::Value), | ||
} | ||
|
||
thread_local! { | ||
// TODO: Make this private | ||
pub static CURSED_OP: Cell<Option<YieldMsg>> = const { Cell::new(None) }; | ||
} | ||
|
||
// TODO: Make private | ||
pub async fn inner() -> Body { | ||
let mut state = false; | ||
poll_fn(|_| match state { | ||
false => { | ||
CURSED_OP.set(Some(YieldMsg::YieldBody)); | ||
state = true; | ||
return Poll::Pending; | ||
} | ||
true => { | ||
let y = CURSED_OP | ||
.take() | ||
.expect("Expected response from outer future!"); | ||
return Poll::Ready(match y { | ||
YieldMsg::YieldBody => unreachable!(), | ||
YieldMsg::YieldBodyResult(body) => Body::Value(body), | ||
}); | ||
} | ||
}) | ||
.await | ||
} | ||
|
||
// TODO: Use this instead | ||
// // Called on `Poll::Pending` from inner | ||
// pub fn outer(waker: &Waker) { | ||
// if let Some(op) = CURSED_OP.take() { | ||
// match op { | ||
// YieldMsg::YieldBody => { | ||
// // TODO: Get proper value | ||
// CURSED_OP.set(Some(YieldMsg::YieldBodyResult(serde_json::Value::Null))); | ||
// waker.wake_by_ref(); | ||
// } | ||
// YieldMsg::YieldBodyResult(_) => unreachable!(), | ||
// } | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,21 @@ | ||
// TODO: Rename | ||
pub trait MwV2Result {} | ||
use serde_json::Value; | ||
|
||
impl MwV2Result for () {} | ||
use crate::error::ExecError; | ||
|
||
/// TODO | ||
pub trait IntoMiddlewareResult { | ||
// TODO: Support streams and bytes | ||
fn into_result(self) -> Result<Value, ExecError>; | ||
} | ||
|
||
impl IntoMiddlewareResult for () { | ||
fn into_result(self) -> Result<Value, ExecError> { | ||
Ok(Value::Null) | ||
} | ||
} | ||
|
||
impl IntoMiddlewareResult for Value { | ||
fn into_result(self) -> Result<Value, ExecError> { | ||
Ok(self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,5 @@ pub mod internal; | |
|
||
// TODO: Only reexport certain types | ||
pub use rspc_core::error::*; | ||
|
||
pub use rspc_core::Body; |