mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-25 09:01:07 -05:00
Merge pull request #1783 from paulkaplan/emit-start-event
Emit a RUNTIME_STARTED event to track if the vm has been started
This commit is contained in:
commit
ffb02c607d
4 changed files with 44 additions and 2 deletions
|
@ -605,6 +605,14 @@ class Runtime extends EventEmitter {
|
||||||
return 'BLOCKSINFO_UPDATE';
|
return 'BLOCKSINFO_UPDATE';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event name when the runtime tick loop has been started.
|
||||||
|
* @const {string}
|
||||||
|
*/
|
||||||
|
static get RUNTIME_STARTED () {
|
||||||
|
return 'RUNTIME_STARTED';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How rapidly we try to step threads by default, in ms.
|
* How rapidly we try to step threads by default, in ms.
|
||||||
*/
|
*/
|
||||||
|
@ -2172,6 +2180,7 @@ class Runtime extends EventEmitter {
|
||||||
this._steppingInterval = setInterval(() => {
|
this._steppingInterval = setInterval(() => {
|
||||||
this._step();
|
this._step();
|
||||||
}, interval);
|
}, interval);
|
||||||
|
this.emit(Runtime.RUNTIME_STARTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -126,6 +126,9 @@ class VirtualMachine extends EventEmitter {
|
||||||
this.runtime.on(Runtime.MIC_LISTENING, listening => {
|
this.runtime.on(Runtime.MIC_LISTENING, listening => {
|
||||||
this.emit(Runtime.MIC_LISTENING, listening);
|
this.emit(Runtime.MIC_LISTENING, listening);
|
||||||
});
|
});
|
||||||
|
this.runtime.on(Runtime.RUNTIME_STARTED, () => {
|
||||||
|
this.emit(Runtime.RUNTIME_STARTED);
|
||||||
|
});
|
||||||
|
|
||||||
this.extensionManager = new ExtensionManager(this.runtime);
|
this.extensionManager = new ExtensionManager(this.runtime);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const test = require('tap').test;
|
const tap = require('tap');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
|
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
|
||||||
const VirtualMachine = require('../../src/virtual-machine');
|
const VirtualMachine = require('../../src/virtual-machine');
|
||||||
|
@ -6,6 +6,10 @@ const Runtime = require('../../src/engine/runtime');
|
||||||
const MonitorRecord = require('../../src/engine/monitor-record');
|
const MonitorRecord = require('../../src/engine/monitor-record');
|
||||||
const {Map} = require('immutable');
|
const {Map} = require('immutable');
|
||||||
|
|
||||||
|
tap.tearDown(() => process.nextTick(process.exit));
|
||||||
|
|
||||||
|
const test = tap.test;
|
||||||
|
|
||||||
test('spec', t => {
|
test('spec', t => {
|
||||||
const r = new Runtime();
|
const r = new Runtime();
|
||||||
|
|
||||||
|
@ -180,3 +184,14 @@ test('Cloud variable limit allows only 8 cloud variables', t => {
|
||||||
t.end();
|
t.end();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Starting the runtime emits an event', t => {
|
||||||
|
let started = false;
|
||||||
|
const rt = new Runtime();
|
||||||
|
rt.addListener('RUNTIME_STARTED', () => {
|
||||||
|
started = true;
|
||||||
|
});
|
||||||
|
rt.start();
|
||||||
|
t.equal(started, true);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const test = require('tap').test;
|
const tap = require('tap');
|
||||||
const VirtualMachine = require('../../src/virtual-machine');
|
const VirtualMachine = require('../../src/virtual-machine');
|
||||||
const Sprite = require('../../src/sprites/sprite');
|
const Sprite = require('../../src/sprites/sprite');
|
||||||
const Variable = require('../../src/engine/variable');
|
const Variable = require('../../src/engine/variable');
|
||||||
|
@ -8,6 +8,10 @@ const Renderer = require('../fixtures/fake-renderer');
|
||||||
const Runtime = require('../../src/engine/runtime');
|
const Runtime = require('../../src/engine/runtime');
|
||||||
const RenderedTarget = require('../../src/sprites/rendered-target');
|
const RenderedTarget = require('../../src/sprites/rendered-target');
|
||||||
|
|
||||||
|
tap.tearDown(() => process.nextTick(process.exit));
|
||||||
|
|
||||||
|
const test = tap.test;
|
||||||
|
|
||||||
test('deleteSound returns function after deleting or null if nothing was deleted', t => {
|
test('deleteSound returns function after deleting or null if nothing was deleted', t => {
|
||||||
const vm = new VirtualMachine();
|
const vm = new VirtualMachine();
|
||||||
const sprite = new Sprite();
|
const sprite = new Sprite();
|
||||||
|
@ -967,3 +971,14 @@ test('Getting the renderer returns the renderer', t => {
|
||||||
t.equal(vm.renderer, renderer);
|
t.equal(vm.renderer, renderer);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Starting the VM emits an event', t => {
|
||||||
|
let started = false;
|
||||||
|
const vm = new VirtualMachine();
|
||||||
|
vm.addListener('RUNTIME_STARTED', () => {
|
||||||
|
started = true;
|
||||||
|
});
|
||||||
|
vm.start();
|
||||||
|
t.equal(started, true);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue