Pipeline
Class
Module: cc.AssetManager
Pipeline can execute the task for some effect.
Index
Properties
id
Number
The id of pipelinename
String
The name of pipelinepipes
Function[]
All pipes of pipeline
Methods
constructor
Create a new pipelineinsert
At specific point insert a new pipe to pipelineappend
Append a new pipe to the pipelineremove
Remove pipe which at specific pointsync
Execute task synchronouslyasync
Execute task asynchronously
Details
Properties
id
The id of pipeline
meta | description |
---|---|
Type | Number |
Defined in | cocos2d/core/asset-manager/pipeline.js:50 |
name
The name of pipeline
meta | description |
---|---|
Type | String |
Defined in | cocos2d/core/asset-manager/pipeline.js:62 |
pipes
All pipes of pipeline
meta | description |
---|---|
Type | Function[] |
Defined in | cocos2d/core/asset-manager/pipeline.js:74 |
Methods
constructor
Create a new pipeline
meta | description |
---|---|
Defined in | cocos2d/core/asset-manager/pipeline.js:97 |
Parameters
name
string The name of pipelinefuncs
Function[] The array of pipe, every pipe must be function which take two parameters, the first is aTask
flowed in pipeline, the second is complete callback
Examples
var pipeline = new Pipeline('download', [
(task, done) => {
var url = task.input;
cc.assetManager.downloader.downloadFile(url, null, null, (err, result) => {
task.output = result;
done(err);
});
},
(task, done) => {
var text = task.input;
var json = JSON.stringify(text);
task.output = json;
done();
}
]);
insert
At specific point insert a new pipe to pipeline
meta | description |
---|---|
Returns | Pipeline |
Defined in | cocos2d/core/asset-manager/pipeline.js:130 |
Parameters
Examples
var pipeline = new Pipeline('test', []);
pipeline.insert((task, done) => {
// do something
done();
}, 0);
append
Append a new pipe to the pipeline
meta | description |
---|---|
Returns | Pipeline |
Defined in | cocos2d/core/asset-manager/pipeline.js:165 |
Parameters
func
Function The new pipe
Examples
var pipeline = new Pipeline('test', []);
pipeline.append((task, done) => {
// do something
done();
});
remove
Remove pipe which at specific point
meta | description |
---|---|
Returns | Pipeline |
Defined in | cocos2d/core/asset-manager/pipeline.js:197 |
Parameters
index
number The specific point
Examples
var pipeline = new Pipeline('test', (task, done) => {
// do something
done();
});
pipeline.remove(0);
sync
Execute task synchronously
meta | description |
---|---|
Returns | Any |
Defined in | cocos2d/core/asset-manager/pipeline.js:227 |
Parameters
task
Task The task will be executed
Examples
var pipeline = new Pipeline('sync', [(task) => {
let input = task.input;
task.output = doSomething(task.input);
}]);
var task = new Task({input: 'test'});
console.log(pipeline.sync(task));
async
Execute task asynchronously
meta | description |
---|---|
Defined in | cocos2d/core/asset-manager/pipeline.js:275 |
Parameters
task
Task The task will be executed
Examples
var pipeline = new Pipeline('sync', [(task, done) => {
let input = task.input;
task.output = doSomething(task.input);
done();
}]);
var task = new Task({input: 'test', onComplete: (err, result) => console.log(result)});
pipeline.async(task);