Skip to content

Instantly share code, notes, and snippets.

@benbr8
benbr8 / box_future.rs
Last active October 5, 2022 18:59
Pass async functions with `BoxFuture`
// [dependencies]
// futures = "*"
// async-std = "*"
use futures::{future::BoxFuture, FutureExt};
use async_std::task;
fn main() {
let mut functions: Vec<fn(usize) -> BoxFuture<'static, usize>> = Vec::new();
@benbr8
benbr8 / async_await.py
Last active December 24, 2023 00:04
Everything there is to know about Python async/await (without asyncio)
class Counter:
def __init__(self, n=3) -> None:
self.n = n
self._cnt = 0
def __await__(self):
for _ in range(self.n):
r = yield self._cnt
print(f"incrementing by {r}")