Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to fix for 1.0 #10

Open
larroy opened this issue May 16, 2015 · 0 comments
Open

Trying to fix for 1.0 #10

larroy opened this issue May 16, 2015 · 0 comments

Comments

@larroy
Copy link

larroy commented May 16, 2015

Hi

I'm trying to fix for 1.0 but I'm stuck in the following:

src/lib.rs:191:13: 197:14 error: match arms have incompatible types:
expected core::result::Result<(), B>,
found ()
(expected enum core::result::Result,
found ()) [E0308]
src/lib.rs:191 match res {
src/lib.rs:192 Ok(val) => {
src/lib.rs:193 let result = thread::scoped(move || func(val)).join();
src/lib.rs:194 p.resolve(result)
src/lib.rs:195 },
src/lib.rs:196 Err(err) => p.fail(err),
...
src/lib.rs:196:29: 196:40 note: match arm with an incompatible type
src/lib.rs:196 Err(err) => p.fail(err),
^~~~~~~~~~~
src/lib.rs:190:14: 198:11 error: type mismatch: the type [closure src/lib.rs:190:29: 198:10] implements the trait core::ops::FnOnce<(core::result::Result<T, FutureError>,)>, but the trait core::ops::FnOnce<()> is required (expected (), found tuple) [E0281]
src/lib.rs:190 self.on_result(move |res: Result<T,FutureError>| {
src/lib.rs:191 match res {
src/lib.rs:192 Ok(val) => {
src/lib.rs:193 let result = thread::scoped(move || func(val)).join();
src/lib.rs:194 p.resolve(result)
src/lib.rs:195 },
...

pub fn map<B, F>(self, func: F) -> Future<B>
    where B: Send, F : FnOnce(T) -> B, T: Send 
{
    let (p ,f) = promise::<B>();
    self.on_result(move |res: Result<T,FutureError>| {
        match res {
            Ok(val) => {
                let result = thread::scoped(move || func(val)).join();
                p.resolve(result)
            },
            Err(err) => p.fail(err),
        };
    });
    f
}

/// Synchronously waits for the result of the Future and returns it.
pub fn get(self) -> Result<T, FutureError> {
    match self.receiver.recv() {
        Ok(res) => res,
        Err(_) => Err(FutureError::HungUp),
    }
}

/// Registers a function f that is called with the result of the Future.
/// This function does not block.
pub fn on_result<F: FnOnce() ->  Result<T, FutureError> + Send>(self, f: F) {
    thread::spawn(move || {
        let result = self.get();
        f(result);
    });
}

why the closure is not getting the type correctly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant