目录
当前位置: 首页 > 文档资料 > Lazy.js 英文文档 >

find

优质
小牛编辑
133浏览
2023-12-01

A version of Sequence#find which returns an AsyncHandle.

Signature

AsyncSequence.find = function(predicate) { /*...*/ }
AsyncSequence.find = function find(predicate) {
  var found;

  var handle = this.each(function(e, i) {
if (predicate(e, i)) {
  found = e;
  return false;
}
  });

  return handle.then(function() { return found; });
}
NameType(s)Description
predicateFunction

A function to call on (potentially) every element in the sequence.

returnsAsyncHandle

An AsyncHandle (promise) which resolves to the found element, once it is detected, or else undefined.