ObjectStatsWatcher
File Stats observation object
When the call fs.watchFile(target, onchange)
is successful, an object of this type is returned
1
2
3
4
5
6
7var fs = require("fs");
var statsWatcher = fs.watchFile(target, (curStat, prevStat) => {
// process
// ...
statsWatcher.unref();
});
Note that the onchange callback will be triggered when and only when the mtime attribute of the observed target file target changes.
Simply accessing the target file target will not trigger the onchange callback.
If fs.watchFile(target)
the file or directory represented by target does not exist when calling , the onchange callback will not be called until the target is created. If the target file is deleted while the watcher is working, then There will be no subsequent callbacks.
inheritance relationship
static properties
defaultMaxListeners
Integer, the default global maximum number of listeners
1static Integer StatsWatcher.defaultMaxListeners;
member properties
onchange
Function, query and bind the "file change" event, equivalent to on("change", func);
1Function StatsWatcher.onchange;
member function
close
Stop observing the target file path and clear the reference count (no longer hold the process)
1StatsWatcher.close();
ref
Increase the reference count and tell fibjs not to exit the process as long as the watcher is still in use.
1StatsWatcher StatsWatcher.ref();
Return results:
- StatsWatcher, returns StatsWatcher itself
The StatsWatcher obtained through fs.watchFile()
has called this method by default, that is, it will hold the process by default.
unref
Decrement reference count
1StatsWatcher StatsWatcher.unref();
Return results:
- StatsWatcher, returns StatsWatcher itself
on
Bind an event handler to the object
1
2Object StatsWatcher.on(String ev,
Function func);
Call parameters:
- ev: String, specifies the name of the event
- func: Function, specify the event processing function
Return results:
- Object, returns the event object itself to facilitate chain calls
Bind an event handler to the object
1Object StatsWatcher.on(Object map);
Call parameters:
- map: Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the value of the attribute will be used as the event processing function
Return results:
- Object, returns the event object itself to facilitate chain calls
addListener
Bind an event handler to the object
1
2Object StatsWatcher.addListener(String ev,
Function func);
Call parameters:
- ev: String, specifies the name of the event
- func: Function, specify the event processing function
Return results:
- Object, returns the event object itself to facilitate chain calls
Bind an event handler to the object
1Object StatsWatcher.addListener(Object map);
Call parameters:
- map: Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the value of the attribute will be used as the event processing function
Return results:
- Object, returns the event object itself to facilitate chain calls
prependListener
Bind an event handler to the object's origin
1
2Object StatsWatcher.prependListener(String ev,
Function func);
Call parameters:
- ev: String, specifies the name of the event
- func: Function, specify the event processing function
Return results:
- Object, returns the event object itself to facilitate chain calls
Bind an event handler to the object's origin
1Object StatsWatcher.prependListener(Object map);
Call parameters:
- map: Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the value of the attribute will be used as the event processing function
Return results:
- Object, returns the event object itself to facilitate chain calls
once
Bind a one-time event handler to the object. The one-time handler will only be triggered once.
1
2Object StatsWatcher.once(String ev,
Function func);
Call parameters:
- ev: String, specifies the name of the event
- func: Function, specify the event processing function
Return results:
- Object, returns the event object itself to facilitate chain calls
Bind a one-time event handler to the object. The one-time handler will only be triggered once.
1Object StatsWatcher.once(Object map);
Call parameters:
- map: Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the value of the attribute will be used as the event processing function
Return results:
- Object, returns the event object itself to facilitate chain calls
prependOnceListener
Bind an event handler to the object's origin
1
2Object StatsWatcher.prependOnceListener(String ev,
Function func);
Call parameters:
- ev: String, specifies the name of the event
- func: Function, specify the event processing function
Return results:
- Object, returns the event object itself to facilitate chain calls
Bind an event handler to the object's origin
1Object StatsWatcher.prependOnceListener(Object map);
Call parameters:
- map: Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the value of the attribute will be used as the event processing function
Return results:
- Object, returns the event object itself to facilitate chain calls
off
Unassign a function from the object processing queue
1
2Object StatsWatcher.off(String ev,
Function func);
Call parameters:
- ev: String, specifies the name of the event
- func: Function, specify the event processing function
Return results:
- Object, returns the event object itself to facilitate chain calls
Cancel all functions in the object processing queue
1Object StatsWatcher.off(String ev);
Call parameters:
- ev: String, specifies the name of the event
Return results:
- Object, returns the event object itself to facilitate chain calls
Unassign a function from the object processing queue
1Object StatsWatcher.off(Object map);
Call parameters:
- map: Object, specifies the event mapping relationship, the object attribute name is used as the event name, and the value of the attribute is used as the event processing function
Return results:
- Object, returns the event object itself to facilitate chain calls
removeListener
Unassign a function from the object processing queue
1
2Object StatsWatcher.removeListener(String ev,
Function func);
Call parameters:
- ev: String, specifies the name of the event
- func: Function, specify the event processing function
Return results:
- Object, returns the event object itself to facilitate chain calls
Cancel all functions in the object processing queue
1Object StatsWatcher.removeListener(String ev);
Call parameters:
- ev: String, specifies the name of the event
Return results:
- Object, returns the event object itself to facilitate chain calls
Unassign a function from the object processing queue
1Object StatsWatcher.removeListener(Object map);
Call parameters:
- map: Object, specifies the event mapping relationship, the object attribute name is used as the event name, and the value of the attribute is used as the event processing function
Return results:
- Object, returns the event object itself to facilitate chain calls
removeAllListeners
Cancels all listeners for all events from the object's processing queue. If an event is specified, removes all listeners for the specified event.
1Object StatsWatcher.removeAllListeners(String ev);
Call parameters:
- ev: String, specifies the name of the event
Return results:
- Object, returns the event object itself to facilitate chain calls
Cancels all listeners for all events from the object's processing queue. If an event is specified, removes all listeners for the specified event.
1Object StatsWatcher.removeAllListeners(Array evs = []);
Call parameters:
- evs: Array, specify the name of the event
Return results:
- Object, returns the event object itself to facilitate chain calls
setMaxListeners
The default limit on the number of listeners, for compatibility only
1StatsWatcher.setMaxListeners(Integer n);
Call parameters:
- n: Integer, specify the number of events
getMaxListeners
Gets the default limit number of listeners, for compatibility only
1Integer StatsWatcher.getMaxListeners();
Return results:
- Integer, returns the default limit quantity
listeners
Query the listener array for the specified event of the object
1Array StatsWatcher.listeners(String ev);
Call parameters:
- ev: String, specifies the name of the event
Return results:
- Array, returns the listener array for the specified event
listenerCount
Query the number of listeners for the specified event of the object
1Integer StatsWatcher.listenerCount(String ev);
Call parameters:
- ev: String, specifies the name of the event
Return results:
- Integer, returns the number of listeners for the specified event
Query the number of listeners for the specified event of the object
1
2Integer StatsWatcher.listenerCount(Value o,
String ev);
Call parameters:
- o: Value, specifies the object of the query
- ev: String, specifies the name of the event
Return results:
- Integer, returns the number of listeners for the specified event
eventNames
Query listener event name
1Array StatsWatcher.eventNames();
Return results:
- Array, returns an array of event names
emit
Actively trigger an event
1
2Boolean StatsWatcher.emit(String ev,
...args);
Call parameters:
- ev: String, event name
- args: ..., event parameters will be passed to the event processing function
Return results:
- Boolean, returns the event trigger status, returns true if there is a response event, otherwise returns false
toString
Returns the string representation of the object. Generally, "[Native Object]" is returned. The object can be re-implemented according to its own characteristics.
1String StatsWatcher.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.
1Value StatsWatcher.toJSON(String key = "");
Call parameters:
- key: String, not used
Return results:
- Value, returns a value containing JSON serializable