Pipeline Class
Module: cc.AssetManager
Pipeline can execute the task for some effect.
Index
Properties
idNumberThe id of pipelinenameStringThe name of pipelinepipesFunction[]All pipes of pipeline
Methods
constructorCreate a new pipelineinsertAt specific point insert a new pipe to pipelineappendAppend a new pipe to the pipelineremoveRemove pipe which at specific pointsyncExecute task synchronouslyasyncExecute 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
namestring The name of pipelinefuncsFunction[] The array of pipe, every pipe must be function which take two parameters, the first is aTaskflowed 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
funcFunction 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
indexnumber 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
taskTask 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
taskTask 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);