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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive task instantiation errors #148

Closed
tzellman opened this issue Apr 27, 2017 · 3 comments
Closed

Recursive task instantiation errors #148

tzellman opened this issue Apr 27, 2017 · 3 comments

Comments

@tzellman
Copy link

For starters, this twiddle demonstrates the issue. I will also state that this may not be a very popular or even valid use case. 馃槃

The error is mainly benign, but does get logged in the console:

Error: tried to advance finished generator
    at Class._takeSafeStep (addon.js:1683)
    at Class._syncResume (addon.js:1785)
    at Class._handleResolvedContinueValue (addon.js:1769)
    at Class._proceed (addon.js:1737)
    at Class.proceed (addon.js:1725)
    at Promise.handleYieldedRsvpPromise [as __ec_yieldable__] (addon.js:1305)
    at cb (addon.js:1310)
    at tryCatch (VM399 ember.debug.js:59069)
    at invokeCallback (VM399 ember.debug.js:59084)
    at publish (VM399 ember.debug.js:59052)
defaultDispatch @ VM399 ember.debug.js:18015
dispatchError @ VM399 ember.debug.js:17994
onerrorDefault @ VM399 ember.debug.js:31641
trigger @ VM399 ember.debug.js:58725
(anonymous) @ VM399 ember.debug.js:59626
invokeWithOnError @ VM399 ember.debug.js:346
flush @ VM399 ember.debug.js:405
flush @ VM399 ember.debug.js:529
end @ VM399 ember.debug.js:599
run @ VM399 ember.debug.js:713
_runExpiredTimers @ VM399 ember.debug.js:1107
Backburner._boundRunExpiredTimers @ VM399 ember.debug.js:568

The use case in mind is similar to how a polling live-reload may work :

  • create a timer-like task that gets kicked off by the app
  • the task likely needs to wait for a period of time, perform some work (e.g. check for new data), then instantiate a new instance so it can do it again

As a workaround either a while(true) could be used inside the task function, or a separate function could be called that defers, then re-instantiates the task.

One thing that I noted from twiddle is that the 0.7.19 version didn't generate the error that 0.8.1 does.

Since the example code to replicate is so small, here it is:

import Ember from 'ember';
import {task, timeout} from 'ember-concurrency';

export default Ember.Controller.extend({
  appName: 'Ember Twiddle',
  count: 0,
  
  recursiveTask: task(function*(){
    yield timeout(1000);
    this.incrementProperty("count", 1);
    this.get("recursiveTask").perform();
  }).restartable(),
  
  init(){
    this.get("recursiveTask").perform();
  }
});
@JackCA
Copy link

JackCA commented Apr 27, 2017

I believe this is the same as the issue I had in this thread: #138 but I closed -- so you're not alone @tzellman

@tzellman
Copy link
Author

Ha! I searched the issues but only the open ones.. Looks like you suggested the same workaround.

I'll leave this open for a bit to possibly get some discussion, even though I'm fine with this not being a supported use case.

I may investigate some alternative approaches as well.

@courajs
Copy link
Contributor

courajs commented Apr 28, 2017

Yeah, this happens when a task cancels itself synchronously:

foo: task(function * () {
  this.get('foo').cancelAll();
})

@machty machty closed this as completed in 8aec0b3 May 4, 2017
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