Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. # fastq
  2. ![ci][ci-url]
  3. [![npm version][npm-badge]][npm-url]
  4. [![Dependency Status][david-badge]][david-url]
  5. Fast, in memory work queue.
  6. Benchmarks (1 million tasks):
  7. * setImmediate: 812ms
  8. * fastq: 854ms
  9. * async.queue: 1298ms
  10. * neoAsync.queue: 1249ms
  11. Obtained on node 12.16.1, on a dedicated server.
  12. If you need zero-overhead series function call, check out
  13. [fastseries](http://npm.im/fastseries). For zero-overhead parallel
  14. function call, check out [fastparallel](http://npm.im/fastparallel).
  15. [![js-standard-style](https://raw.githubusercontent.com/feross/standard/master/badge.png)](https://github.com/feross/standard)
  16. * <a href="#install">Installation</a>
  17. * <a href="#usage">Usage</a>
  18. * <a href="#api">API</a>
  19. * <a href="#license">Licence &amp; copyright</a>
  20. ## Install
  21. `npm i fastq --save`
  22. ## Usage (callback API)
  23. ```js
  24. 'use strict'
  25. const queue = require('fastq')(worker, 1)
  26. queue.push(42, function (err, result) {
  27. if (err) { throw err }
  28. console.log('the result is', result)
  29. })
  30. function worker (arg, cb) {
  31. cb(null, arg * 2)
  32. }
  33. ```
  34. ## Usage (promise API)
  35. ```js
  36. const queue = require('fastq').promise(worker, 1)
  37. async function worker (arg) {
  38. return arg * 2
  39. }
  40. async function run () {
  41. const result = await queue.push(42)
  42. console.log('the result is', result)
  43. }
  44. run()
  45. ```
  46. ### Setting "this"
  47. ```js
  48. 'use strict'
  49. const that = { hello: 'world' }
  50. const queue = require('fastq')(that, worker, 1)
  51. queue.push(42, function (err, result) {
  52. if (err) { throw err }
  53. console.log(this)
  54. console.log('the result is', result)
  55. })
  56. function worker (arg, cb) {
  57. console.log(this)
  58. cb(null, arg * 2)
  59. }
  60. ```
  61. ### Using with TypeScript (callback API)
  62. ```ts
  63. 'use strict'
  64. import * as fastq from "fastq";
  65. import type { queue, done } from "fastq";
  66. type Task = {
  67. id: number
  68. }
  69. const q: queue<Task> = fastq(worker, 1)
  70. q.push({ id: 42})
  71. function worker (arg: Task, cb: done) {
  72. console.log(arg.id)
  73. cb(null)
  74. }
  75. ```
  76. ### Using with TypeScript (promise API)
  77. ```ts
  78. 'use strict'
  79. import * as fastq from "fastq";
  80. import type { queueAsPromised } from "fastq";
  81. type Task = {
  82. id: number
  83. }
  84. const q: queueAsPromised<Task> = fastq.promise(asyncWorker, 1)
  85. q.push({ id: 42}).catch((err) => console.error(err))
  86. async function asyncWorker (arg: Task): Promise<void> {
  87. // No need for a try-catch block, fastq handles errors automatically
  88. console.log(arg.id)
  89. }
  90. ```
  91. ## API
  92. * <a href="#fastqueue"><code>fastqueue()</code></a>
  93. * <a href="#push"><code>queue#<b>push()</b></code></a>
  94. * <a href="#unshift"><code>queue#<b>unshift()</b></code></a>
  95. * <a href="#pause"><code>queue#<b>pause()</b></code></a>
  96. * <a href="#resume"><code>queue#<b>resume()</b></code></a>
  97. * <a href="#idle"><code>queue#<b>idle()</b></code></a>
  98. * <a href="#length"><code>queue#<b>length()</b></code></a>
  99. * <a href="#getQueue"><code>queue#<b>getQueue()</b></code></a>
  100. * <a href="#kill"><code>queue#<b>kill()</b></code></a>
  101. * <a href="#killAndDrain"><code>queue#<b>killAndDrain()</b></code></a>
  102. * <a href="#error"><code>queue#<b>error()</b></code></a>
  103. * <a href="#concurrency"><code>queue#<b>concurrency</b></code></a>
  104. * <a href="#drain"><code>queue#<b>drain</b></code></a>
  105. * <a href="#empty"><code>queue#<b>empty</b></code></a>
  106. * <a href="#saturated"><code>queue#<b>saturated</b></code></a>
  107. * <a href="#promise"><code>fastqueue.promise()</code></a>
  108. -------------------------------------------------------
  109. <a name="fastqueue"></a>
  110. ### fastqueue([that], worker, concurrency)
  111. Creates a new queue.
  112. Arguments:
  113. * `that`, optional context of the `worker` function.
  114. * `worker`, worker function, it would be called with `that` as `this`,
  115. if that is specified.
  116. * `concurrency`, number of concurrent tasks that could be executed in
  117. parallel.
  118. -------------------------------------------------------
  119. <a name="push"></a>
  120. ### queue.push(task, done)
  121. Add a task at the end of the queue. `done(err, result)` will be called
  122. when the task was processed.
  123. -------------------------------------------------------
  124. <a name="unshift"></a>
  125. ### queue.unshift(task, done)
  126. Add a task at the beginning of the queue. `done(err, result)` will be called
  127. when the task was processed.
  128. -------------------------------------------------------
  129. <a name="pause"></a>
  130. ### queue.pause()
  131. Pause the processing of tasks. Currently worked tasks are not
  132. stopped.
  133. -------------------------------------------------------
  134. <a name="resume"></a>
  135. ### queue.resume()
  136. Resume the processing of tasks.
  137. -------------------------------------------------------
  138. <a name="idle"></a>
  139. ### queue.idle()
  140. Returns `false` if there are tasks being processed or waiting to be processed.
  141. `true` otherwise.
  142. -------------------------------------------------------
  143. <a name="length"></a>
  144. ### queue.length()
  145. Returns the number of tasks waiting to be processed (in the queue).
  146. -------------------------------------------------------
  147. <a name="getQueue"></a>
  148. ### queue.getQueue()
  149. Returns all the tasks be processed (in the queue). Returns empty array when there are no tasks
  150. -------------------------------------------------------
  151. <a name="kill"></a>
  152. ### queue.kill()
  153. Removes all tasks waiting to be processed, and reset `drain` to an empty
  154. function.
  155. -------------------------------------------------------
  156. <a name="killAndDrain"></a>
  157. ### queue.killAndDrain()
  158. Same than `kill` but the `drain` function will be called before reset to empty.
  159. -------------------------------------------------------
  160. <a name="error"></a>
  161. ### queue.error(handler)
  162. Set a global error handler. `handler(err, task)` will be called
  163. when any of the tasks return an error.
  164. -------------------------------------------------------
  165. <a name="concurrency"></a>
  166. ### queue.concurrency
  167. Property that returns the number of concurrent tasks that could be executed in
  168. parallel. It can be altered at runtime.
  169. -------------------------------------------------------
  170. <a name="drain"></a>
  171. ### queue.drain
  172. Function that will be called when the last
  173. item from the queue has been processed by a worker.
  174. It can be altered at runtime.
  175. -------------------------------------------------------
  176. <a name="empty"></a>
  177. ### queue.empty
  178. Function that will be called when the last
  179. item from the queue has been assigned to a worker.
  180. It can be altered at runtime.
  181. -------------------------------------------------------
  182. <a name="saturated"></a>
  183. ### queue.saturated
  184. Function that will be called when the queue hits the concurrency
  185. limit.
  186. It can be altered at runtime.
  187. -------------------------------------------------------
  188. <a name="promise"></a>
  189. ### fastqueue.promise([that], worker(arg), concurrency)
  190. Creates a new queue with `Promise` apis. It also offers all the methods
  191. and properties of the object returned by [`fastqueue`](#fastqueue) with the modified
  192. [`push`](#pushPromise) and [`unshift`](#unshiftPromise) methods.
  193. Node v10+ is required to use the promisified version.
  194. Arguments:
  195. * `that`, optional context of the `worker` function.
  196. * `worker`, worker function, it would be called with `that` as `this`,
  197. if that is specified. It MUST return a `Promise`.
  198. * `concurrency`, number of concurrent tasks that could be executed in
  199. parallel.
  200. <a name="pushPromise"></a>
  201. #### queue.push(task) => Promise
  202. Add a task at the end of the queue. The returned `Promise` will be fulfilled
  203. when the task is processed.
  204. <a name="unshiftPromise"></a>
  205. #### queue.unshift(task) => Promise
  206. Add a task at the beginning of the queue. The returned `Promise` will be fulfilled
  207. when the task is processed.
  208. ## License
  209. ISC
  210. [ci-url]: https://github.com/mcollina/fastq/workflows/ci/badge.svg
  211. [npm-badge]: https://badge.fury.io/js/fastq.svg
  212. [npm-url]: https://badge.fury.io/js/fastq
  213. [david-badge]: https://david-dm.org/mcollina/fastq.svg
  214. [david-url]: https://david-dm.org/mcollina/fastq