官术网_书友最值得收藏!

  • Node.js Design Patterns
  • Mario Casciaro Luciano Mammino
  • 210字
  • 2021-06-18 18:15:07

Exercises

  • 3.1 A simple event: Modify the asynchronous FindRegex class so that it emits an event when the find process starts, passing the input files list as an argument. Hint: beware of Zalgo!
  • 3.2 Ticker: Write a function that accepts a number and a callback as the arguments. The function will return an EventEmitter that emits an event called tick every 50 milliseconds until the number of milliseconds is passed from the invocation of the function. The function will also call the callback when the number of milliseconds has passed, providing, as the result, the total count of tick events emitted. Hint: you can use setTimeout() to schedule another setTimeout() recursively.
  • 3.3 A simple modification: Modify the function created in exercise 3.2 so that it emits a tick event immediately after the function is invoked.
  • 3.4 Playing with errors: Modify the function created in exercise 3.3 so that it produces an error if the timestamp at the moment of a tick (including the initial one that we added as part of exercise 3.3) is pisible by 5. Propagate the error using both the callback and the event emitter. Hint: use Date.now() to get the timestamp and the remainder (%) operator to check whether the timestamp is pisible by 5.
主站蜘蛛池模板: 崇明县| 元氏县| 于田县| 通化县| 旌德县| 东城区| 盐城市| 咸宁市| 富源县| 滨海县| 黄冈市| 鄯善县| 敖汉旗| 赞皇县| 五原县| 大埔县| 枣阳市| 凤凰县| 肇源县| 大英县| 新沂市| 浠水县| 南宁市| 黄平县| 深州市| 吴川市| 千阳县| 新乡市| 柏乡县| 南召县| 泗水县| 罗甸县| 屏边| 石家庄市| 丰城市| 兴化市| 独山县| 泸定县| 府谷县| 壤塘县| 开远市|