# FFI and functions and/or closures

**URL:** <https://discuss.moonbitlang.com/t/ffi-and-functions-and-or-closures/210>\
**Category:** Development\
**Created:** [April 22, 2024, 12:32am UTC](https://discuss.moonbitlang.com/t/ffi-and-functions-and-or-closures/210 "2024-04-22T00:32:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayphelps](https://discuss.moonbitlang.com/letter_avatar_proxy/v4/letter/j/4491bb/32.png) [@jayphelps](https://discuss.moonbitlang.com/u/jayphelps)\
**Post date:** [April 22, 2024, 12:32am UTC](https://discuss.moonbitlang.com/t/ffi-and-functions-and-or-closures/210/1 "2024-04-22T00:32:53Z")

</div>

```auto
pub fn schedule_timeout(callback : () -> Int, delay : Int) -> Unit = "env" "schedule_timeout"

```

When I attempt to use the FFI to directly pass a function or closure I get `Invalid stub type`. I assume that’s because doing so isn’t currently supported, which is pretty understanding at this point in the language.

I’m trying to do things like timers/intervals. I’m already working around this this limitation by having some scheduler logic inside moonbit code that has a single exported callback that will then delegate to the right interval timer callbacks, but I’m curious what the long-term thinking is on FFI and functions? I imagine that’ll be quite some time, if ever? I know the ABI isn’t stable yet.

---

<div class="post-metadata">

**Author:** ![peter-jerry-ye](https://discuss.moonbitlang.com/user_avatar/discuss.moonbitlang.com/peter-jerry-ye/32/97_2.png) [@peter-jerry-ye](https://discuss.moonbitlang.com/u/peter-jerry-ye)\
**Post date:** [April 22, 2024, 1:58am UTC](https://discuss.moonbitlang.com/t/ffi-and-functions-and-or-closures/210/2 "2024-04-22T01:58:07Z")

</div>

We’re expecting to lift some restrictions this week (i.e. to be published next week). We’re focusing on this issue right now and we will provide an experimental solution soon.
