Skip to content

Commit 620dd8a

Browse files
committed
Experimenting with request API
Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai>
1 parent 10fdc36 commit 620dd8a

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

src/request.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
use crate::{
1919
OutputChain, UnusedTarget, InputBundle, StreamPack, Provider,
20-
ModifiersUnset, AddOperation, Noop, IntoAsyncMap,
20+
ModifiersUnset, AddOperation, Noop, IntoAsyncMap, Promise,
2121
};
2222

23-
use bevy::prelude::Commands;
23+
use bevy::prelude::{Commands, Entity, Bundle};
2424

2525
use std::future::Future;
2626

@@ -119,6 +119,47 @@ async fn async_server<T: Future>(value: T) -> T::Output {
119119
value.await
120120
}
121121

122+
pub struct Target<Response, Streams> {
123+
session: Entity,
124+
_ignore: std::marker::PhantomData<(Response, Streams)>
125+
}
126+
127+
impl<Response, Streams> Target<Response, Streams> {
128+
/// If the target is dropped, the request will not be cancelled.
129+
pub fn detach(self) -> Target<Response, Streams> {
130+
131+
}
132+
133+
/// Take the data that comes out of the request.
134+
#[must_use]
135+
pub fn take(self) -> Recipient<Response, Streams> {
136+
137+
}
138+
139+
/// Pass the outcome of the request to another provider.
140+
#[must_use]
141+
pub fn then<P: Provider<Request = Response>>(
142+
self,
143+
provider: Provider,
144+
) -> Target<P::Response, P::Streams> {
145+
146+
}
147+
}
148+
149+
impl<Response, Streams> Target<Response, Streams>
150+
where
151+
Response: Bundle,
152+
{
153+
pub fn store(self, target: Entity) {
154+
155+
}
156+
}
157+
158+
pub struct Recipient<Response, Streams: StreamPack> {
159+
pub response: Promise<Response>,
160+
pub streams: Streams::Receiver,
161+
}
162+
122163
#[cfg(test)]
123164
mod tests {
124165
use crate::{*, testing::*};

src/stream.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
use bevy::prelude::{Component, Bundle, Entity, Commands, World};
1919

20+
use crossbeam::channel::Receiver;
21+
2022
use crate::{
2123
InputSlot, Output, UnusedTarget, RedirectWorkflowStream, RedirectScopeStream,
2224
AddOperation, OperationRoster, OperationResult, OrBroken, ManageInput,
@@ -118,6 +120,7 @@ pub trait StreamPack: 'static + Send + Sync {
118120
type StreamStorageBundle: Bundle;
119121
type StreamInputPack;
120122
type StreamOutputPack;
123+
type Receiver;
121124

122125
fn spawn_scope_streams(scope: Entity, commands: &mut Commands) -> (
123126
Self::StreamStorageBundle,
@@ -140,6 +143,7 @@ impl<T: Stream> StreamPack for T {
140143
type StreamStorageBundle = StreamTargetStorage<Self>;
141144
type StreamInputPack = InputSlot<Self>;
142145
type StreamOutputPack = Output<Self>;
146+
type Receiver = Receiver<Self>;
143147

144148
fn spawn_scope_streams(scope: Entity, commands: &mut Commands) -> (
145149
Self::StreamStorageBundle,
@@ -168,6 +172,7 @@ impl StreamPack for () {
168172
type StreamStorageBundle = ();
169173
type StreamInputPack = ();
170174
type StreamOutputPack = ();
175+
type Receiver = ();
171176

172177
fn spawn_scope_streams(_: Entity, _: &mut Commands) -> (
173178
Self::StreamStorageBundle,
@@ -196,6 +201,7 @@ impl<T1: StreamPack> StreamPack for (T1,) {
196201
type StreamStorageBundle = T1::StreamStorageBundle;
197202
type StreamInputPack = T1::StreamInputPack;
198203
type StreamOutputPack = T1::StreamOutputPack;
204+
type Receiver = T1::Receiver;
199205

200206
fn spawn_scope_streams(scope: Entity, commands: &mut Commands) -> (
201207
Self::StreamStorageBundle,
@@ -224,6 +230,7 @@ impl<T1: StreamPack, T2: StreamPack> StreamPack for (T1, T2) {
224230
type StreamStorageBundle = (T1::StreamStorageBundle, T2::StreamStorageBundle);
225231
type StreamInputPack = (T1::StreamInputPack, T2::StreamInputPack);
226232
type StreamOutputPack = (T1::StreamOutputPack, T2::StreamOutputPack);
233+
type Receiver = (T1::Receiver, T2::Receiver);
227234

228235
fn spawn_scope_streams(scope: Entity, commands: &mut Commands) -> (
229236
Self::StreamStorageBundle,
@@ -258,6 +265,7 @@ impl<T1: StreamPack, T2: StreamPack, T3: StreamPack> StreamPack for (T1, T2, T3)
258265
type StreamStorageBundle = (T1::StreamStorageBundle, T2::StreamStorageBundle, T3::StreamStorageBundle);
259266
type StreamInputPack = (T1::StreamInputPack, T2::StreamInputPack, T3::StreamInputPack);
260267
type StreamOutputPack = (T1::StreamOutputPack, T2::StreamOutputPack, T3::StreamOutputPack);
268+
type Receiver = (T1::Receiver, T2::Receiver, T3::Receiver);
261269

262270
fn spawn_scope_streams(scope: Entity, commands: &mut Commands) -> (
263271
Self::StreamStorageBundle,

0 commit comments

Comments
 (0)