mirror of
https://github.com/nasa/openmct.git
synced 2024-12-21 22:17:49 +00:00
parent
dc85d3c191
commit
7d911a3fe0
@ -9,6 +9,7 @@
|
||||
"platform/commonUI/general",
|
||||
"platform/commonUI/inspect",
|
||||
"platform/containment",
|
||||
"platform/execution",
|
||||
"platform/telemetry",
|
||||
"platform/features/layout",
|
||||
"platform/features/pages",
|
||||
|
1
platform/execution/README.md
Normal file
1
platform/execution/README.md
Normal file
@ -0,0 +1 @@
|
||||
Contains services which manage execution and flow control (e.g. for concurrency.)
|
10
platform/execution/bundle.json
Normal file
10
platform/execution/bundle.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"extensions": {
|
||||
"services": [
|
||||
{
|
||||
"key": "workerService",
|
||||
"depends": [ "$window", "workers[]" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
68
platform/execution/src/WorkerService.js
Normal file
68
platform/execution/src/WorkerService.js
Normal file
@ -0,0 +1,68 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* as represented by the Administrator of the National Aeronautics and Space
|
||||
* Administration. All rights reserved.
|
||||
*
|
||||
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Handles the execution of WebWorkers.
|
||||
* @constructor
|
||||
*/
|
||||
function WorkerService($window, workers) {
|
||||
var workerUrls = {},
|
||||
Worker = $window.Worker;
|
||||
|
||||
function addWorker(worker) {
|
||||
var key = worker.key;
|
||||
if (!workerUrls[key]) {
|
||||
workerUrls[key] = [
|
||||
worker.bundle.path,
|
||||
worker.bundle.sources,
|
||||
worker.scriptUrl
|
||||
].join("/");
|
||||
}
|
||||
}
|
||||
|
||||
(workers || []).forEach(addWorker);
|
||||
|
||||
return {
|
||||
/**
|
||||
* Start running a new web worker. This will run a worker
|
||||
* that has been registered under the `workers` category
|
||||
* of extension.
|
||||
*
|
||||
* @param {string} key symbolic identifier for the worker
|
||||
* @returns {Worker} the running Worker
|
||||
*/
|
||||
run: function (key) {
|
||||
var scriptUrl = workerUrls[key];
|
||||
return scriptUrl && Worker && new Worker(scriptUrl);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return WorkerService;
|
||||
}
|
||||
);
|
77
platform/execution/test/WorkerServiceSpec.js
Normal file
77
platform/execution/test/WorkerServiceSpec.js
Normal file
@ -0,0 +1,77 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* as represented by the Administrator of the National Aeronautics and Space
|
||||
* Administration. All rights reserved.
|
||||
*
|
||||
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
/*global define,describe,it,expect,beforeEach,jasmine*/
|
||||
|
||||
define(
|
||||
["../src/WorkerService"],
|
||||
function (WorkerService) {
|
||||
"use strict";
|
||||
|
||||
describe("The worker service", function () {
|
||||
var mockWindow,
|
||||
testWorkers,
|
||||
mockWorker,
|
||||
service;
|
||||
|
||||
beforeEach(function () {
|
||||
mockWindow = jasmine.createSpyObj('$window', ['Worker']);
|
||||
testWorkers = [
|
||||
{
|
||||
key: 'abc',
|
||||
scriptUrl: 'c.js',
|
||||
bundle: { path: 'a', sources: 'b' }
|
||||
},
|
||||
{
|
||||
key: 'xyz',
|
||||
scriptUrl: 'z.js',
|
||||
bundle: { path: 'x', sources: 'y' }
|
||||
},
|
||||
{
|
||||
key: 'xyz',
|
||||
scriptUrl: 'bad.js',
|
||||
bundle: { path: 'bad', sources: 'bad' }
|
||||
}
|
||||
];
|
||||
mockWorker = {};
|
||||
|
||||
mockWindow.Worker.andReturn(mockWorker);
|
||||
|
||||
service = new WorkerService(mockWindow, testWorkers);
|
||||
});
|
||||
|
||||
it("instantiates workers at registered paths", function () {
|
||||
expect(service.run('abc')).toBe(mockWorker);
|
||||
expect(mockWindow.Worker).toHaveBeenCalledWith('a/b/c.js');
|
||||
});
|
||||
|
||||
it("prefers the first worker when multiple keys are found", function () {
|
||||
expect(service.run('xyz')).toBe(mockWorker);
|
||||
expect(mockWindow.Worker).toHaveBeenCalledWith('x/y/z.js');
|
||||
});
|
||||
|
||||
it("returns undefined for unknown workers", function () {
|
||||
expect(service.run('def')).toBeUndefined();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
3
platform/execution/test/suite.json
Normal file
3
platform/execution/test/suite.json
Normal file
@ -0,0 +1,3 @@
|
||||
[
|
||||
"WorkerService"
|
||||
]
|
Loading…
Reference in New Issue
Block a user