What type is a FuturesUnordered?

I need to have a

static FOO: Lazy<RwLock<FuturesUnordered<T>>> ...

and then I need to push() onto it. but what type should that T be? and how exactly would I push futures onto it?

If possible I'd like to see an example

The documentation for FuturesUnordered uses Fut instead of T, which makes me think this type contains other futures. This would make sense, since it is "a set of futures in no particular order". The type T is probably a concrete Future type.

One trick to find what type something should have is to use a type that definitely isn't correct, and have the compiler tell you the right type:

// compiler will indicate that this is a &str, not a ()
let foo: () = "hello";
1 Like

If the future is created with an async block you can't name its type, so it'd be best to box it, Pin<Box<dyn Future>>. Maybe add + Send there if it's necessary.

FOO.write().push(Box::pin(async {}));

Yes, it is the type of future stored in the FuturesUnordered. You probably want to use a boxed future in this case.

thanks, this is what I needed.