mirror of
				https://github.com/rust-lang/rust.git
				synced 2025-10-31 13:04:42 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			21 lines
		
	
	
		
			458 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			21 lines
		
	
	
		
			458 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
| //@ edition: 2021
 | |
| 
 | |
| #![feature(async_closure, noop_waker)]
 | |
| 
 | |
| use std::future::Future;
 | |
| use std::pin::pin;
 | |
| use std::task::*;
 | |
| 
 | |
| pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
 | |
|     let mut fut = pin!(fut);
 | |
|     // Poll loop, just to test the future...
 | |
|     let ctx = &mut Context::from_waker(Waker::noop());
 | |
| 
 | |
|     loop {
 | |
|         match unsafe { fut.as_mut().poll(ctx) } {
 | |
|             Poll::Pending => {}
 | |
|             Poll::Ready(t) => break t,
 | |
|         }
 | |
|     }
 | |
| }
 | 
