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

Fix Merge System #243

Merged
merged 4 commits into from
Aug 25, 2017
Merged

Fix Merge System #243

merged 4 commits into from
Aug 25, 2017

Conversation

zakarumych
Copy link
Member

Fix Merge System
Futures can't be polled without Task.
Spawn creates such Task and provide API to run inner Future
Without this Merge will panic! when it'll try to call Future::poll except if it is trivial custom Future

Copy link
Member

@torkleyy torkleyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! There are a few nits to resolve and I'd like to get rid of RefCell.

src/common.rs Outdated
}
}

static NOTIFY_IGNORE: &&'static NotifyIgnore = &&NotifyIgnore;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for lifetimes in static items.

src/common.rs Outdated
self.spawns.push(RefCell::new((e, spawn(futures.remove(e).unwrap()))));
}

self.spawns.retain(|spawn| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to get rid of RefCell, we can use

let len = spawns.len();
let mut del = 0;
{
    for i in 0..len {
        let remove = { /* Do stuff */ };

        if remove {
            del += 1;
        } else if del > 0 {
            spawns.swap(i - del, i);
        }
    }
}
if del > 0 {
    spawns.truncate(len - del);
}

You can also just make this a helper function. The fact that retain only allows immutable access was a design mistake.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! That's basically exactly what I wrote for SmallVec's retain function. I love code re-use.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is almost like my first variant 😄

src/common.rs Outdated
use std::convert::AsRef;
use std::error::Error;
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
use std::io::Write;
use std::marker::PhantomData;

use futures::{Async, Future};
use futures::executor::{Notify, spawn, Spawn};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reorder so that spawn is at the end.

src/common.rs Outdated
struct NotifyIgnore;
impl Notify for NotifyIgnore {
fn notify(&self, _: usize) {
/* Intentionally ignore */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use line comment.

@torkleyy
Copy link
Member

When I tried the system out it worked, so yeah, maybe my Future was trivial.

Copy link
Member

@torkleyy torkleyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@torkleyy torkleyy self-assigned this Aug 25, 2017
@torkleyy torkleyy added the bug label Aug 25, 2017
@torkleyy torkleyy requested a review from kvark August 25, 2017 15:49
@torkleyy
Copy link
Member

It would be really nice to have a test / an example using futures, so we can validate it actually works now.

@Xaeroxe
Copy link
Member

Xaeroxe commented Aug 25, 2017

Shared is a really easy way to generate a panic if this isn't working, as it depends on task::current()

@torkleyy
Copy link
Member

Okay, I'm going to merge this, but I would like to add an example before releasing a new version. We could also port this fix back to 0.9 if you want to.

bors r+

bors bot added a commit that referenced this pull request Aug 25, 2017
243: Fix Merge System r=torkleyy a=omni-viral

Fix `Merge` `System`
`Future`s can't be `poll`ed without `Task`.
`Spawn` creates such `Task` and provide API to run inner `Future`
Without this `Merge` will `panic!` when it'll try to call `Future::poll` except if it is trivial custom `Future`
@bors
Copy link
Contributor

bors bot commented Aug 25, 2017

Build succeeded

@bors bors bot merged commit 7f78506 into amethyst:master Aug 25, 2017
torkleyy pushed a commit to torkleyy/specs that referenced this pull request Aug 26, 2017
This ports a bug fix by @omni-viral
back to 0.9

This includes the following commits:

Poll on Spawn, not on Future

Do not require Spawn to be Sync

Fix typo

Get rid of RefCell
@torkleyy torkleyy mentioned this pull request Aug 26, 2017
bors bot added a commit that referenced this pull request Aug 26, 2017
245: Backport #243 to 0.9 r=torkleyy a=torkleyy

This ports a bug fix ( #243 ) by @omni-viral
back to 0.9

This includes the following commits:

* Poll on Spawn, not on Future
* Do not require Spawn to be Sync
* Fix typo
* Get rid of RefCell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants