Skip to content
Eugene Lazutkin edited this page Nov 26, 2019 · 4 revisions

io.track tracks I/O requests in flight. Duplicated requests are not issued, but a promise for an unfinished request is reused. It allows to register requests initiated outside of io, and register requests without initiating an I/O. io.track serves as a companion for cache and bundle services.

Don't forget to consult the cookbook to see working snippets solving simple real-world problems.

Logic

If options object has a Boolean property track, it tells the track service to process or ignore a request. Otherwise, a default algorithm is used described in Service documentation.

Exposed properties

Like any service, io.track works transparently with io, but it exposes some helpers.

io.track.fly(options)

This function takes options of an I/O request, and returns a promise, which will be resolved when an I/O is finished. It can be used to register an I/O already in progress started outside of io.

io.track.isFlying(options)

This function checks, if an I/O request described by options is marked as "in-flight". It returns a false value, if the request is unknown, or a corresponding deferred object.

If io is instrumented to use the standard Promise, its deferred object contains three property:

  • promise — a corresponding promise object.
  • resolve(value) — a method to resolve a promise with value.
  • reject(value) — a method to reject a promise with value.

If io uses FastDeferred or Deferred of heya-async, it exposes one more useful method:

  • progress(value) — a method to report a progress with value.

And its promise has one more method:

  • cancel(reason) — a method to cancel waiting for a promise.

See more details in heya-async wiki and docs on Deferred.Promise.

io.track.flyByKey(key)

This function is similar to io.track.fly(options), but takes a key rather than options. See io.makeKey() of the main API for more details.

The function is used to implement io.track.fly(), and exposed for efficiency.

io.track.deferred

This is a dictionary object to keep track of I/O requests in flight. Keys are unique keys generated by io.makeKey(). Values are deferred objects described above in io.track.isFlying().

Standard service properties

See Service documentation for more details.

Clone this wiki locally