Comments (5)
@ef4 Each of these queues is an Orbit TaskQueue
. When the queues are empty they emit a complete
event, which you can listen for:
currentSource.requestQueue.on('complete', () => {
// optionally return a promise here if you want to delay future actions of the queue until the promise resolves or errors
});
Remember to cleanup with off
.
from ember-orbit.
Thanks. Is there a corresponding event for going from empty to active?
from ember-orbit.
beforeTask
is emitted before each task in the queue is processed. I think this is most like an "active" indicator.
Another event to be aware of is change
which is emitted whenever the contents of the queue change, but this may happen when the queue is complete or processing has paused and its contents are changed.
from ember-orbit.
Thanks, that set me on the right track. I ended up going with beforeTask
for start and task
or fail
for end. Here is a utility that may help others (and could potentially go into ember-orbit):
import { buildWaiter } from '@ember/test-waiters';
export function buildOrbitWaiter(label) {
let waiter = buildWaiter(label);
const taskTokens = new WeakMap();
function taskStarted(task) {
let token = waiter.beginAsync();
taskTokens.set(task, token);
}
function taskEnded(task) {
let token = taskTokens.get(task);
if (token) {
waiter.endAsync(token);
}
}
function waitForSource(source) {
source.requestQueue.on('beforeTask', taskStarted);
source.requestQueue.on('task', taskEnded);
source.requestQueue.on('fail', taskEnded);
source.syncQueue.on('beforeTask', taskStarted);
source.syncQueue.on('task', taskEnded);
source.syncQueue.on('fail', taskEnded);
return source;
}
return { waitForSource };
}
You use it like:
import JSONAPISource from '@orbit/jsonapi';
import { buildOrbitWaiter } from '../lib/orbit-waiter';
let { waitForSource } = buildOrbitWaiter('data-source:rails');
export default {
create(injections = {}) {
return waitForSource(new JSONAPISource(injections));
}
}
from ember-orbit.
Looks good @ef4 - thanks for sharing! I've opened tracking issue #341 to ensure that we add your work, or something similar, to ember-orbit soon.
from ember-orbit.
Related Issues (20)
- TS issues HOT 2
- Dependencies not defined in ember-orbit, like @orbit/local-storage-bucket not propagated through addons HOT 1
- Adding a validation function to the data models in orbit HOT 2
- Merging a fork when using IndexedDb causes error HOT 3
- Provide better integration with Ember's new test waiters system
- Throws unintended exception while trying to assert about hasMany with no arg HOT 1
- Best pattern for load+fork HOT 4
- Synchronous in-memory addRecord HOT 4
- Detecting yet-to-be-loaded models HOT 4
- IndexedDB error adding new model type HOT 4
- [Beta 15] Removed from cache errors HOT 7
- Improve handling of bucket injections for ember v4 compat.
- Upgrading to 0.17 with custom serializers HOT 1
- No 'attributes' saved to indexeddb HOT 1
- Access to relationships.*.data.id HOT 3
- Irregular noun record type doesn't sync to store HOT 4
- The get attribute cache lookup error is hard to debug
- Included ( second level ) data is not passing through Orbit if they are not cached !
- Typescript compatibility issues HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-orbit.