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

Getting result from coroutines #47

Closed
3Hren opened this issue Jul 1, 2015 · 4 comments
Closed

Getting result from coroutines #47

3Hren opened this issue Jul 1, 2015 · 4 comments

Comments

@3Hren
Copy link

3Hren commented Jul 1, 2015

Hi!

Are you planning to add an ability to extract results from finished coroutines, like it is implemented in Thread?

Something like this:

let coro = Coroutine::spawn(move || {
    42
});

let res = coro.join().unwrap();
assert_eq!(42, res);
@3Hren 3Hren changed the title Getting result from coroutine Getting result from coroutines Jul 1, 2015
@zonyitoo
Copy link
Contributor

zonyitoo commented Jul 1, 2015

Then, what's the return type of resume? Result<Option<T>>?

If the parent and its children are not running in the same thread, then the return result must be transferred from this thread to another thread. This is also an obstacle of implementing #48 .

@3Hren
Copy link
Author

3Hren commented Jul 1, 2015

Hmm, good catch. Then, this issue seems like a subset of #48.

@therustmonk
Copy link
Contributor

With #68 it's possible:

let mut coro = Coroutine::spawn(move |me,_| {
    42
});
let result = coro.resume(0);

We haven't return types larger than usize. For custom types pointers have to be used, like I do there. If we add something like Result<T> we'll increase overhead for coroutines which don't need results quite.

I think this issue should be closed.

@zonyitoo
Copy link
Contributor

You are right.

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

3 participants