Object built-in object

ObjectChain

Message handler chain processing object

The Chain object is a message processor chain processing object in fibjs, which is used to link a series of message processors and process them in a specified order. The method to create a Chain object is as follows:

1 2 3
var chain = new mq.Chain([ func1, func2 ]);

In this creation method, both func1 and func2 are function objects of the message processor. The Chain object links these processors together in order to form a processor chain. When processing each message, the processor can perform customized processing on the message, and then hand the message to the next processor for processing. In this way, a message can be processed step by step to the final state.

The invoke() function of the Chain object is used to process a message or object. When this function is called, the Chain object passes the message or object to each processor in turn, processing it in processor order until all processors have processed it. During this process, each processor can perform customized processing on the message or object, or choose to pass the message or object to the next processor for processing.

In practical applications, Chain objects can be applied to various scenarios. For example, in a web framework, request messages can be passed to each processor in sequence for processing; in a message queue, a batch of messages can be passed to each processor in sequence. for processing. The use of Chain objects is very flexible and can be customized according to actual needs. It is highly scalable and reusable.

inheritance relationship

Constructor

Chain

Construct a message handler chain processing object

1
new Chain(Array hdlrs);

Call parameters:

  • hdlrs: Array, processor array

member function

append

Add processor array

1
Chain.append(Array hdlrs);

Call parameters:

  • hdlrs: Array, processor array

Add processor

1
Chain.append(Handler hdlr);

Call parameters:

  • hdlr:Handler, built-in message processor, processing function, chain processing array, routing object, see detailsmq.Handler

invoke

Process a message or object

1
Handler Chain.invoke(object v) async;

Call parameters:

  • v:object, specify the message or object to be processed

Return results:

  • Handler, return to the next processor

toString

Returns the string representation of the object. Generally, "[Native Object]" is returned. The object can be re-implemented according to its own characteristics.

1
String Chain.toString();

Return results:

  • String, returns the string representation of the object

toJSON

Returns a JSON format representation of the object, generally returning a collection of readable properties defined by the object.

1
Value Chain.toJSON(String key = "");

Call parameters:

  • key: String, not used

Return results:

  • Value, returns a value containing JSON serializable