VulpesOS/gaia/apps/calendar/test/unit/provider/mock_stream.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

68 lines
1.2 KiB
JavaScript
Executable file

define(function(require, exports, module) {
'use strict';
var Responder = require('common/responder');
function MockStream() {
Responder.call(this);
this._queue = [];
this._workingQueue = false;
}
module.exports = MockStream;
var emit = Responder.prototype.emit;
MockStream.prototype = {
__proto__: Responder.prototype,
emit: function() {
var args = Array.prototype.slice.call(arguments);
var self = this;
this._queue.push(function() {
emit.apply(self, args);
});
this._workQueue();
},
request: function(callback) {
if (this._requestCallback) {
throw new Error('request may only be called once.');
}
this._requestCallback = callback;
if (this.mockonrequest) {
this.mockonrequest();
}
},
_workQueue: function() {
if (!this._workingQueue && this._queue.length) {
var self = this;
var next = this._queue.shift();
this._workingQueue = true;
setTimeout(function() {
next();
self._workingQueue = false;
self._workQueue();
}, 0);
}
},
close: function() {
var self = this;
this._queue.push(function() {
self._requestCallback.apply(self, arguments);
});
this._workQueue();
}
};
});