- 前言
- Lazy
- createWrapper
- generate
- range
- repeat
- strict
- Sequence
- define
- async
- chunk
- compact
- concat
- consecutive
- contains
- countBy
- dropWhile
- each
- equals
- every
- filter
- find
- findWhere
- first
- flatten
- get
- getIterator
- groupBy
- indexBy
- indexOf
- initial
- intersection
- invoke
- isEmpty
- join
- last
- lastIndexOf
- map
- max
- memoize
- min
- none
- ofType
- pluck
- reduce
- reduceRight
- reject
- rest
- reverse
- shuffle
- size
- some
- sort
- sortBy
- sortedIndex
- sum
- takeWhile
- tap
- toArray
- toObject
- union
- uniq
- where
- without
- zip
- ArrayLikeSequence
- define
- concat
- first
- get
- length
- map
- pop
- push
- rest
- reverse
- shift
- slice
- unshift
- ObjectLikeSequence
- define
- assign
- async
- defaults
- functions
- get
- invert
- keys
- merge
- omit
- pairs
- pick
- toArray
- toObject
- values
- watch
- StringLikeSequence
- define
- charAt
- charCodeAt
- contains
- endsWith
- first
- indexOf
- last
- lastIndexOf
- mapString
- match
- reverse
- split
- startsWith
- substring
- toLowerCase
- toUpperCase
- GeneratedSequence
- each
- length
- AsyncSequence
- contains
- each
- find
- getIterator
- indexOf
- Iterator
- current
- moveNext
- AsyncHandle
- cancel
- onComplete
- onError
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
AsyncHandle
An AsyncHandle
provides a Promises/A+ compliant interface for an AsyncSequence that is currently (or was) iterating over its elements.
In addition to behaving as a promise, an AsyncHandle
provides the ability to AsyncHandle#cancel iteration (if cancelFn
is provided) and also offers convenient AsyncHandle#onComplete and AsyncHandle#onError methods to attach listeners for when iteration is complete or an error is thrown during iteration.
Signature
function AsyncHandle(cancelFn) { /*...*/ }
function AsyncHandle(cancelFn) { this.resolveListeners = []; this.rejectListeners = []; this.state = PENDING; this.cancelFn = cancelFn; }
Name | Type(s) | Description |
---|---|---|
cancelFn | Function | A function to cancel asynchronous iteration. This is passed in to support different cancellation mechanisms for different forms of asynchronous sequences (e.g., timeout-based sequences, sequences based on I/O, etc.). |
Examples
// Create a sequence of 100,000 random numbers, in chunks of 100. var sequence = Lazy.generate(Math.random) .chunk(100) .async() .take(1000); // Reduce-style operations -- i.e., operations that return a *value* (as // opposed to a *sequence*) -- return an AsyncHandle for async sequences. var handle = sequence.toArray(); handle.onComplete(function(array) { // Do something w/ 1,000-element array. }); // Since an AsyncHandle is a promise, you can also use it to create // subsequent promises using `then` (see the Promises/A+ spec for more // info). var flattened = handle.then(function(array) { return Lazy(array).flatten(); });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论