|
1 | 1 | use std::{any::Any, cell::RefCell, future::Future, panic::AssertUnwindSafe, pin::Pin}; |
2 | 2 |
|
3 | 3 | use async_std::task; |
4 | | -use futures::prelude::*; |
| 4 | +use futures::FutureExt; |
5 | 5 | use pyo3::prelude::*; |
6 | 6 |
|
7 | 7 | use crate::{ |
@@ -488,3 +488,61 @@ where |
488 | 488 | pub fn into_future(awaitable: &PyAny) -> PyResult<impl Future<Output = PyResult<PyObject>> + Send> { |
489 | 489 | generic::into_future::<AsyncStdRuntime>(awaitable) |
490 | 490 | } |
| 491 | + |
| 492 | +/// Convert async generator into a stream |
| 493 | +/// |
| 494 | +/// # Availability |
| 495 | +/// |
| 496 | +/// **This API is marked as unstable** and is only available when the |
| 497 | +/// `unstable-streams` crate feature is enabled. This comes with no |
| 498 | +/// stability guarantees, and could be changed or removed at any time. |
| 499 | +#[cfg(feature = "unstable-streams")] |
| 500 | +pub fn into_stream_v1<'p>( |
| 501 | + gen: &'p PyAny, |
| 502 | +) -> PyResult<impl futures::Stream<Item = PyResult<PyObject>> + 'static> { |
| 503 | + generic::into_stream_v1::<AsyncStdRuntime>(gen) |
| 504 | +} |
| 505 | + |
| 506 | +/// Convert async generator into a stream |
| 507 | +/// |
| 508 | +/// # Availability |
| 509 | +/// |
| 510 | +/// **This API is marked as unstable** and is only available when the |
| 511 | +/// `unstable-streams` crate feature is enabled. This comes with no |
| 512 | +/// stability guarantees, and could be changed or removed at any time. |
| 513 | +#[cfg(feature = "unstable-streams")] |
| 514 | +pub fn into_stream_with_locals_v1<'p>( |
| 515 | + locals: TaskLocals, |
| 516 | + gen: &'p PyAny, |
| 517 | +) -> PyResult<impl futures::Stream<Item = PyResult<PyObject>> + 'static> { |
| 518 | + generic::into_stream_with_locals_v1::<AsyncStdRuntime>(locals, gen) |
| 519 | +} |
| 520 | + |
| 521 | +/// Convert async generator into a stream |
| 522 | +/// |
| 523 | +/// # Availability |
| 524 | +/// |
| 525 | +/// **This API is marked as unstable** and is only available when the |
| 526 | +/// `unstable-streams` crate feature is enabled. This comes with no |
| 527 | +/// stability guarantees, and could be changed or removed at any time. |
| 528 | +#[cfg(feature = "unstable-streams")] |
| 529 | +pub fn into_stream_with_locals_v2<'p>( |
| 530 | + locals: TaskLocals, |
| 531 | + gen: &'p PyAny, |
| 532 | +) -> PyResult<impl futures::Stream<Item = PyObject> + 'static> { |
| 533 | + generic::into_stream_with_locals_v2::<AsyncStdRuntime>(locals, gen) |
| 534 | +} |
| 535 | + |
| 536 | +/// Convert async generator into a stream |
| 537 | +/// |
| 538 | +/// # Availability |
| 539 | +/// |
| 540 | +/// **This API is marked as unstable** and is only available when the |
| 541 | +/// `unstable-streams` crate feature is enabled. This comes with no |
| 542 | +/// stability guarantees, and could be changed or removed at any time. |
| 543 | +#[cfg(feature = "unstable-streams")] |
| 544 | +pub fn into_stream_v2<'p>( |
| 545 | + gen: &'p PyAny, |
| 546 | +) -> PyResult<impl futures::Stream<Item = PyObject> + 'static> { |
| 547 | + generic::into_stream_v2::<AsyncStdRuntime>(gen) |
| 548 | +} |
0 commit comments