opened
glasser
username_0
I think it makes sense that if registerPromise is called after unmount, that it should return something like `new Promise(() => {})`, ie a Promise that never will resolve.

I ran into this in this situation: I had forgotten to register one particular Promise, and so the component unmounted (because of a client-side redirect that occurred on page load) before most of my Promises even ran, and so the fact that I registered later Promises was irrelevant.

Here's how I'm using this by the way:

```js
  componentDidMount() {
    this.pollInterval = setInterval(() => this.poll(), 30 * 1000);
    this.poll();
  }
  componentWillUnmount() {
    if (this.pollInterval) {
      clearInterval(this.pollInterval);
      this.pollInterval = null;
    }
  }
  poll() {
    this.props.registerPromise(Promise.resolve())
      .then(() => this.props.registerPromise(this.checkStatus()))
      .then(details => details || this.props.registerPromise(this.checkIncident()))
      .then(details => details || this.props.registerPromise(this.checkMaintenance()))
      .then(details => this.setState({details}));
  }
```

When I was missing the registerPromise around the initial Promise.resolve() I would trigger the issue described here every time I loaded the page that did a redirect (and thus a component unmount) on startup.

Arguably this was me mis-using the API by forgetting a registration, but it still seems like this should have been able to work.
Maybe should pre-trash Promises if registerPromise called after unmount?
issue
created
hjylewis
username_1
Hmm, interesting. So I don't want to encourage calling `registerPromise` after unmounting since that references `this` and prevents the React object from getting GC'd.

But on the other hand, what happens *now* when you don't have the `registerPromise` around the initial `Promise.resolve()`? Do to promises go on to be called? 😬
comment
created
glasser
username_0
Yep!

So arguably maybe the (or "a") problem is that I'm registering the promise asynchronously, and I should only ever be calling registerPromise at a time that is "known untrashed"?

Honestly I kinda just want to have to call registerPromise once and have it be "viral".

ie, maybe sooooomehow, the way that base `trashable` should work is that if you trash a Promise, you automatically trash any Promise made from a chain of `then` or `catch` on it too. Is that too awful?
comment
created
hjylewis
username_1
Yeah, I think that would be the goal. It IS annoying to have to wrap all those chained promises.

If we were able to create an actual TrashablePromise as proposed [here](https://github.com/username_1/trashable/issues/6#issuecomment-348322130) in username_1/trashable#6, we might be able to wrap the returned values of the handles to chain together Trashable Promises so you could write:
```
    this.props.registerPromise(Promise.resolve())
      .then(() => this.firstPromise())
      .then(() => this.secondPromise())
      .then(() => this.thirdPromise());
```
instead of:
```
    this.props.registerPromise(Promise.resolve())
      .then(() => this.props.registerPromise(this.firstPromise()))
      .then(() => this.props.registerPromise(this.secondPromise()))
      .then(() => this.props.registerPromise(this.thirdPromise()));
```
Which would be great. Not sure if possible though...
comment