खोज…


परिचय

वायदा-आरएस एक पुस्तकालय है जो शून्य लागत फ्यूचर्स और धाराओं को रस्ट में लागू करता है।

फ्यूचर क्रेट की मुख्य अवधारणाएं फ्यूचर और स्ट्रीम हैं ।

भविष्य समारोह के साथ एक भविष्य बनाना

फ्यूचर क्रेट में कुछ सामान्य Future ट्रेल कार्यान्वयन हैं। उनमें से एक futures::sync::oneshot में लागू किया गया है futures::sync::oneshot मॉड्यूल और futures::oneshot माध्यम से उपलब्ध है futures::oneshot फ़ंक्शन:

extern crate futures;

use std::thread;
use futures::Future;

fn expensive_computation() -> u32 {
    // ...
    200
}

fn main() {
    // The oneshot function returns a tuple of a Sender and a Receiver.
    let (tx, rx) = futures::oneshot();

    thread::spawn(move || {
        // The complete method resolves a values.
        tx.complete(expensive_computation());
    });

    // The map method applies a function to a value, when it is resolved.
    let rx = rx.map(|x| {
        println!("{}", x);
    });

    // The wait method blocks current thread until the value is resolved.
    rx.wait().unwrap();
}


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow