fix: wait for immediate particles

This commit is contained in:
cha0s 2021-01-21 19:27:44 -06:00
parent cbc9449005
commit 2793d99ab5

View File

@ -1,5 +1,4 @@
import {PI_180} from '@avocado/math';
import {resource} from '@avocado/resource';
import {Ticker} from '@avocado/timing';
import {Trait} from '@avocado/traits';
import {compose} from '@latus/core';
@ -91,7 +90,7 @@ export default (latus) => class Emitter extends decorate(Trait) {
}
async emitParticleJson(json) {
const {fromResourceType: {Entity}} = resource(latus);
const {Entity} = latus.get('%resources.fromResourceType');
return this.entity.emitParticleEntity(await Entity.load(json));
}
@ -200,11 +199,13 @@ export default (latus) => class Emitter extends decorate(Trait) {
} = json;
const stream = K.stream((emitter) => {
if (0 === rate) {
const promises = [];
for (let i = 0; i < count; ++i) {
this.emitParticleJson(json).then((particle) => {
promises.push(this.emitParticleJson(json).then((particle) => {
emitter.emit(particle);
});
}));
}
Promise.all(promises).then(() => emitter.end());
}
else {
const ticker = new Ticker(rate);
@ -230,10 +231,8 @@ export default (latus) => class Emitter extends decorate(Trait) {
}
});
this.#emissions.push(ticker);
return;
}
}
emitter.end();
});
// Always make sure something listens...
stream.onEnd(() => {});