Skip to content

Instantly share code, notes, and snippets.

@dsafonov-grid
Created July 25, 2022 10:25
Show Gist options
  • Save dsafonov-grid/e146782aaa3e1bf6225764a8068b4671 to your computer and use it in GitHub Desktop.
Save dsafonov-grid/e146782aaa3e1bf6225764a8068b4671 to your computer and use it in GitHub Desktop.
New Twiddle
/* eslint-disable require-yield */
import Component from '@glimmer/component';
import { task, timeout, waitForProperty } from 'ember-concurrency';
export default class EventsExampleComponent extends Component {
// BEGIN-SNIPPET waitForProperty
@task
*changeStore() {
this.foo.perform();
this.bar.perform();
}
@task *foo() {
yield timeout(1000);
return 'all good';
}
@task *bar() {
let value = yield waitForProperty(this, 'foo.isIdle');
alert(value);
}
}
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
<h3>waitProperty bug demo: waitProperty doesn't seem to work when waiting for task's isIdle property to change</h3>
<p>
Expected behavior: when foo task completes, its isIdle property should become true, and the
waitForProperty(this, 'foo.isIdle') in the bar task should complete and bar should continue executing.
Actual behavior: bar task gets stuck on waitForProperty(this, 'foo.isIdle') even when foo.isIdle becomes true
</p>
<button {{on "click" (perform this.changeStore)}} type="button">
Start
</button>
<h5>
{{!-- State: {{this.state}} --}}
</h5>
<h5>
{{!-- foo.isIdle: {{foo.isIdle}} --}}
</h5>
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
"ember-source": "3.28.9"
},
"addons": {
"@glimmer/component": "1.1.2",
"ember-concurrency": "2.2.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment