You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <p align="center">
  2. <a href="http://gulpjs.com">
  3. <img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
  4. </a>
  5. </p>
  6. # last-run
  7. [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url]
  8. Capture and retrieve the last time a function was run.
  9. ## Usage
  10. ```js
  11. var lastRun = require('last-run');
  12. function myFunc(){}
  13. myFunc();
  14. // capture the run after (or before) calling the function
  15. lastRun.capture(myFunc);
  16. // retrieve the last run time
  17. lastRun(myFunc);
  18. //-> outputs the Date.now() when capture was called
  19. ```
  20. ## API
  21. __Note: this module uses a WeakMap shim, and throws on non-extensible functions on platforms that
  22. don't have a native WeakMap implementation__
  23. ### lastRun(fn, [timeResolution]) => [Timestamp]
  24. Takes a function (`fn`) and returns a timestamp of the last time the function was captured.
  25. Returns undefined if the function has not been captured.
  26. The timestamp is always given in millisecond but the time resolution can be reduced (rounded down).
  27. The use case is to be able to compare a build time to a file time attribute.
  28. On node v0.10 or with file system like HFS or FAT, `fs.stat` time attributes like `mtime` precision is one second.
  29. Assuming `lastRun(fn)` returns 1426000001111, `lastRun(fn, 1000)` returns 1426000001000.
  30. The default time resolution is 1000 on node v0.10, 0 on node 0.11+ and iojs.
  31. More information at [`default-resolution`][default-resolution] and
  32. [undertaker PR #17][undertaker-17].
  33. ### lastRun.capture(fn, [timestamp])
  34. Takes a function (`fn`) and captures the current timestamp with `Date.now()`.
  35. If passed the optional timestamp, captures that time instead of `Date.now()`.
  36. The captured timestamp can then be retrieved using the `lastRun` function.
  37. ### lastRun.release(fn)
  38. Takes a function (`fn`) and removes the last run timestamp for it.
  39. ## License
  40. MIT
  41. [default-resolution]: https://github.com/gulpjs/default-resolution
  42. [undertaker-17]: https://github.com/gulpjs/undertaker/pull/17#issuecomment-82374512
  43. [downloads-image]: http://img.shields.io/npm/dm/last-run.svg
  44. [npm-url]: https://www.npmjs.com/package/last-run
  45. [npm-image]: http://img.shields.io/npm/v/last-run.svg
  46. [travis-url]: https://travis-ci.org/gulpjs/last-run
  47. [travis-image]: http://img.shields.io/travis/gulpjs/last-run.svg?label=travis-ci
  48. [appveyor-url]: https://ci.appveyor.com/project/gulpjs/last-run
  49. [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/last-run.svg?label=appveyor
  50. [coveralls-url]: https://coveralls.io/r/gulpjs/last-run
  51. [coveralls-image]: http://img.shields.io/coveralls/gulpjs/last-run/master.svg
  52. [gitter-url]: https://gitter.im/gulpjs/gulp
  53. [gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg