# Passing async function or closure as parameter

**URL:** <https://forum.dfinity.org/t/passing-async-function-or-closure-as-parameter/21785>\
**Category:** Rust\
**Created:** [July 28, 2023, 4:35pm UTC](https://forum.dfinity.org/t/passing-async-function-or-closure-as-parameter/21785 "2023-07-28T16:35:04Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [July 30, 2023, 12:23pm UTC](https://forum.dfinity.org/t/passing-async-function-or-closure-as-parameter/21785/9 "2023-07-30T12:23:51Z")

</div>

If someone ever lands on this in the future, here a sample async function passed as parameter which can be run in the Rust playground:

```auto
use std::future::Future;

type MyParam = u64;
type MyResult = u64;

async fn count(
    value: MyParam,
) -> MyResult {
    value + 1
}

async fn execute<F, Fut>(
    f: F,
    value: MyParam,
) -> MyResult
where
    F: FnOnce(MyParam) -> Fut,
    Fut: Future<Output = MyResult>,
{
    f(value).await
}

#[tokio::main]
async fn main() {
    let value = execute(count, 1).await;
    println!("{:?}", value);
}

```

---

_[View the full topic](https://forum.dfinity.org/t/passing-async-function-or-closure-as-parameter/21785)._
