Pipeline Class

Module: cc.AssetManager

Pipeline can execute the task for some effect.

Index

Properties
  • id Number The id of pipeline
  • name String The name of pipeline
  • pipes Function[] All pipes of pipeline
Methods
  • constructor Create a new pipeline
  • insert At specific point insert a new pipe to pipeline
  • append Append a new pipe to the pipeline
  • remove Remove pipe which at specific point
  • sync Execute task synchronously
  • async 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 pipeline
  • funcs Function[] The array of pipe, every pipe must be function which take two parameters, the first is a Task 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
  • func Function The new pipe
    • task Task The task handled with pipeline will be transferred to this function
    • callback Function Callback you need to invoke manually when this pipe is finished. if the pipeline is synchronous, callback is unnecessary.
  • index number The specific point you want to insert at.
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
    • task Task The task handled with pipeline will be transferred to this function
    • callback Function Callback you need to invoke manually when this pipe is finished. if the pipeline is synchronous, callback is unnecessary.
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);

results matching ""

    No results matching ""