Object built-in object

Object StatsWatcher

File Stats Observed Object

When calling fs.watchFile(target, onchange) successfully, return this type of object

1 2 3 4 5 6 7
var fs = require("fs"); var statsWatcher = fs.watchFile(target, (curStat, prevStat) => { // process // ... statsWatcher.unref(); });

Note 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 when fs.watchFile(target) is called, the file or directory represented by the target does not yet exist, the onchange callback will not be called. The callback will not be called until the target is created. If the watcher is working,) If the target file is deleted, there will be no subsequent callbacks

Inheritance

Static properties

defaultMaxListeners

Integer, the default global maximum number of listeners

1
static Integer StatsWatcher.defaultMaxListeners;

Member attributes

onchange

Function, query and bind "file change" event, equivalent to on("change", func);

1
Function StatsWatcher.onchange;

Member function

close

Stop observing the target file path and clear the reference count (no longer hold the process)

1
StatsWatcher.close();

ref

Increase the reference count and tell fibjs not to exit the process as long as the watcher is still in use.

1
StatsWatcher StatsWatcher.ref();

Return result:

  • StatsWatcher , returns StatsWatcher itself

The StatsWatcher obtained via fs.watchFile() has called this method by default, that is, the process is held by default.


unref

Reduce reference count

1
StatsWatcher StatsWatcher.unref();

Return result:

  • StatsWatcher , returns StatsWatcher itself

on

Bind an event handler to the object

1 2
Object StatsWatcher.on(String ev, Function func);

Call parameters:

  • ev : String, specify the name of the event
  • func : Function, specify event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

Bind an event handler to the object

1
Object StatsWatcher.on(Object map);

Call parameters:

  • map : Object, specify the event mapping relationship, the object property name will be the event name, and the property value will be the event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

addListener

Bind an event handler to the object

1 2
Object StatsWatcher.addListener(String ev, Function func);

Call parameters:

  • ev : String, specify the name of the event
  • func : Function, specify event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

Bind an event handler to the object

1
Object StatsWatcher.addListener(Object map);

Call parameters:

  • map : Object, specify the event mapping relationship, the object property name will be the event name, and the property value will be the event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

prependListener

Bind an event handler to the object start

1 2
Object StatsWatcher.prependListener(String ev, Function func);

Call parameters:

  • ev : String, specify the name of the event
  • func : Function, specify event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

Bind an event handler to the object start

1
Object StatsWatcher.prependListener(Object map);

Call parameters:

  • map : Object, specify the event mapping relationship, the object property name will be the event name, and the property value will be the event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

once

Bind a one-time event processing function to the object, the one-time processing function will only be triggered once

1 2
Object StatsWatcher.once(String ev, Function func);

Call parameters:

  • ev : String, specify the name of the event
  • func : Function, specify event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

Bind a one-time event processing function to the object, the one-time processing function will only be triggered once

1
Object StatsWatcher.once(Object map);

Call parameters:

  • map : Object, specify the event mapping relationship, the object property name will be the event name, and the property value will be the event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

prependOnceListener

Bind an event handler to the object start

1 2
Object StatsWatcher.prependOnceListener(String ev, Function func);

Call parameters:

  • ev : String, specify the name of the event
  • func : Function, specify event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

Bind an event handler to the object start

1
Object StatsWatcher.prependOnceListener(Object map);

Call parameters:

  • map : Object, specify the event mapping relationship, the object property name will be the event name, and the property value will be the event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

off

Cancel the specified function from the object processing queue

1 2
Object StatsWatcher.off(String ev, Function func);

Call parameters:

  • ev : String, specify the name of the event
  • func : Function, specify event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

Cancel all functions in the object processing queue

1
Object StatsWatcher.off(String ev);

Call parameters:

  • ev : String, specify the name of the event

Return result:

  • Object , returns the event object itself, easy to chain call

Cancel the specified function from the object processing queue

1
Object StatsWatcher.off(Object map);

Call parameters:

  • map : Object, specify the event mapping relationship, the object property name is used as the event name, and the property value is used as the event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

removeListener

Cancel the specified function from the object processing queue

1 2
Object StatsWatcher.removeListener(String ev, Function func);

Call parameters:

  • ev : String, specify the name of the event
  • func : Function, specify event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

Cancel all functions in the object processing queue

1
Object StatsWatcher.removeListener(String ev);

Call parameters:

  • ev : String, specify the name of the event

Return result:

  • Object , returns the event object itself, easy to chain call

Cancel the specified function from the object processing queue

1
Object StatsWatcher.removeListener(Object map);

Call parameters:

  • map : Object, specify the event mapping relationship, the object property name is used as the event name, and the property value is used as the event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

removeAllListeners

Cancel all listeners of all events from the object processing queue. If an event is specified, remove all listeners of the specified event.

1
Object StatsWatcher.removeAllListeners(Array evs = []);

Call parameters:

  • evs : Array, specify the name of the event

Return result:

  • Object , returns the event object itself, easy to chain call

setMaxListeners

The default limit of the number of listeners, only for compatibility

1
StatsWatcher.setMaxListeners(Integer n);

Call parameters:

  • n : Integer, specify the number of events

getMaxListeners

Get the default limit of the number of listeners, only for compatibility

1
Integer StatsWatcher.getMaxListeners();

Return result:

  • Integer , returns the default limit number

listeners

Array of listeners for the specified event of the query object

1
Array StatsWatcher.listeners(String ev);

Call parameters:

  • ev : String, specify the name of the event

Return result:

  • Array , returns an array of listeners for the specified event

listenerCount

The number of listeners for the specified event of the query object

1
Integer StatsWatcher.listenerCount(String ev);

Call parameters:

  • ev : String, specify the name of the event

Return result:

  • Integer , returns the number of listeners for the specified event

eventNames

Query listener event name

1
Array StatsWatcher.eventNames();

Return result:

  • Array , returns an array of event names

emit

Actively trigger an event

1 2
Boolean StatsWatcher.emit(String ev, ...args);

Call parameters:

  • ev : String, event name
  • args : ..., event parameters, which will be passed to the event handler

Return result:

  • 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 returns "[Native Object]", the object can be re-implemented according to its own characteristics

1
String StatsWatcher.toString();

Return result:

  • String , returns the string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object

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

Call parameters:

  • key : String, unused

Return result:

  • Value , returns a value containing JSON serializable