mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-10 06:52:00 -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';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
@ -2172,6 +2180,7 @@ class Runtime extends EventEmitter {
|
|||
this._steppingInterval = setInterval(() => {
|
||||
this._step();
|
||||
}, interval);
|
||||
this.emit(Runtime.RUNTIME_STARTED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -126,6 +126,9 @@ class VirtualMachine extends EventEmitter {
|
|||
this.runtime.on(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);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const test = require('tap').test;
|
||||
const tap = require('tap');
|
||||
const path = require('path');
|
||||
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
|
||||
const VirtualMachine = require('../../src/virtual-machine');
|
||||
|
@ -6,6 +6,10 @@ const Runtime = require('../../src/engine/runtime');
|
|||
const MonitorRecord = require('../../src/engine/monitor-record');
|
||||
const {Map} = require('immutable');
|
||||
|
||||
tap.tearDown(() => process.nextTick(process.exit));
|
||||
|
||||
const test = tap.test;
|
||||
|
||||
test('spec', t => {
|
||||
const r = new Runtime();
|
||||
|
||||
|
@ -180,3 +184,14 @@ test('Cloud variable limit allows only 8 cloud variables', t => {
|
|||
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 Sprite = require('../../src/sprites/sprite');
|
||||
const Variable = require('../../src/engine/variable');
|
||||
|
@ -8,6 +8,10 @@ const Renderer = require('../fixtures/fake-renderer');
|
|||
const Runtime = require('../../src/engine/runtime');
|
||||
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 => {
|
||||
const vm = new VirtualMachine();
|
||||
const sprite = new Sprite();
|
||||
|
@ -967,3 +971,14 @@ test('Getting the renderer returns the renderer', t => {
|
|||
t.equal(vm.renderer, renderer);
|
||||
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