1.0.0 • Published 1 year ago

@f1stnpm2/corporis-ea-a v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@f1stnpm2/corporis-ea-a

Combine async iterators into an object that conforms to theasync iterable and async iterator protocol.

Installation

npm i @f1stnpm2/corporis-ea-a

AsyncIteratorsCombine

Yields an array (method: all or allSettled) or a single value (method: race or any) when the passed promise concurrency method returns a value. Return when the first async iterator returns (lazy: true) or return when the last async iterator returns (lazy: false)

new AsyncIteratorsCombine(
  iterable,
  {
    returnAsyncIterators = Array.from(iterable),
    method = 'all',
    lazy = false,
    initialValue = undefined,
  } = {}
)
  • iterable (required): AsyncIterator[]
  • options (optional): an object that has the following optional properties:
    • method: 'all', 'allSettled', 'race', 'any' (default: all)`
    • lazy: true, false (default: false)
      • Return when the the first async iterator returns or return when the last async iterator returns.
    • initialValue: any (default: undefined)
      • The initial value for an async iterator that has not yet yielded.
    • returnAsyncIterators: AsyncIterator[](default: all async iterators that are passed into iterable)
      • All async iterators that are passed into returnAsyncIterators are returned when the combined async iterator is returned.

CombineLatest

Yields an array of all latest yielded values for every async iterator. Start when the first async iterator yields (eager: true) or start when all async iterators have yielded (eager: false).

new CombineLatest(
  iterable,
  {
    returnAsyncIterators = Array.from(iterable),
    eager = false,
    lazy = false,
    initialValue = undefined,
  } = {}
)

Examples

import { AsyncIteratorsCombine } from '@f1stnpm2/corporis-ea-a';

async function* generator1() {
  yield 1;
  yield 2;
  yield 3;
}

async function* generator2() {
  yield 'a';
  yield 'b';
  yield 'c';
  yield 'd';
  yield 'e';
}

const combination = new AsyncIteratorsCombine([generator1, generator2]);

for await (const output of combination) {
  console.log(output); // -> [1, 'a'], [2, 'b'], [3, 'c'], [3, 'd'], [3, 'e']
}

const combination2 = new AsyncIteratorsCombine([generator1, generator2], { lazy: true });

for await (const output of combination2) {
  console.log(output); // -> [1, 'a'], [2, 'b'], [3, 'c']
}
import { AsyncIteratorsCombine } from '@f1stnpm2/corporis-ea-a';

async function* generator1() {
  await new Promise((resolve) => {
    setTimeout(resolve, 100);
  });
  yield 1;
  await new Promise((resolve) => {
    setTimeout(resolve, 100);
  });
  yield 2;
  await new Promise((resolve) => {
    setTimeout(resolve, 100);
  });
  yield 3;
}

async function* generator2() {
  await new Promise((resolve) => {
    setTimeout(resolve, 50);
  });
  yield 'a';
  await new Promise((resolve) => {
    setTimeout(resolve, 20);
  });
  yield 'b';
  await new Promise((resolve) => {
    setTimeout(resolve, 100);
  });
  yield 'c';
}

const combination = new AsyncIteratorsCombine([generator1, generator2], { method: 'race' });

for await (const output of combination) {
  console.log(output); // -> 'a', 'b', 1, 'c', 2, 3
}

const combination2 = new AsyncIteratorsCombine([generator1, generator2], {
  method: 'race',
  lazy: true,
});

for await (const output of combination2) {
  console.log(output); // -> 'a', 'b', 1, 'c'
}
import { CombineLatest } from '@f1stnpm2/corporis-ea-a';

async function* generator1() {
  await new Promise((resolve) => {
    setTimeout(resolve, 100);
  });
  yield 1;
  await new Promise((resolve) => {
    setTimeout(resolve, 100);
  });
  yield 2;
  await new Promise((resolve) => {
    setTimeout(resolve, 100);
  });
  yield 3;
}

async function* generator2() {
  await new Promise((resolve) => {
    setTimeout(resolve, 50);
  });
  yield 'a';
  await new Promise((resolve) => {
    setTimeout(resolve, 20);
  });
  yield 'b';
  await new Promise((resolve) => {
    setTimeout(resolve, 100);
  });
  yield 'c';
}

const combination = new CombineLatest([generator1, generator2]);

for await (const output of combination) {
  console.log(output); // -> [1, 'a'], [1, 'b'], [1, 'c'], [2, 'c'], [3, 'c']
}

const combination2 = new CombineLatest([generator1, generator2], {
  eager: true,
});

for await (const output of combination2) {
  console.log(output); // -> [undefined, 'a'], [undefined, 'b'], [1, 'c'], [2, 'c'], [3, 'c']
}
watchingserializationdataviewjsdiffdefineprunequeuechromeECMAScript 2019colourArrayBuffer#slicees2016concurrencyrangeerrorexpressionbeanstalkcss-in-jsfast-deep-clonepyyamlesviewUnderscoreiteratormonorepoassertflatMapjwtinferencetypedarraysgraphqlchineseemojiMicrosoftYAMLpushclassnamesInt32Arrayperformancees2018warningslotelasticacheforEachsqssortedpatchweakmapexitpropertiesquerystringappoptimizerBigUint64ArrayJSON-SchemaObject.fromEntriesairbnbclassesless compilertelephonejsdomextensionreadwrapjasminecopypackagedom-testing-libraryECMAScript 2020fromspecArray.prototype.includesflagtouchStreamsbreakcreateenvironmentcloneraterm -frwalking256stringifyoncestylesheetidlegroupByfastifymimeconsoletraversesortlook-upfindinstallertypanionwatcherdeep-clonemiddlewareconcatMapsetPrototypeOfmakeFloat64Arraymkdirinterruptsclass-validatorfetchbusygetopthasES6writablehasOwnES2019cloudfrontguidObservablesincludesdependency managertimechannelmkdirpwordbreakcryptoelmhigher-ordertapestablecallboundmodulehttpscss nestingsomeReactiveExtensionsrfc4122emrentriesESrestsymbolreact-hook-formchaieslint-pluginlintRxreplaygetPrototypeOfinputmake dirparsermovecall-boundtrimStartoptimistTypedArrayprivatenumbertypedstylecommanderdomttynested csscolordatawhatwgpostcss-pluginnativepathAsyncIteratormulti-packageWeakSetjsonpathcollectionStreamstoragegatewaycloudtrailtypedarrayajvcjklength-0polyfillECMAScript 7ECMAScript 2015RFC-6455isConcatSpreadablelesscssfiltercallbinditeratekeyreal-timenamesFloat32Arraycolumnsstylesnodejscss variableES2016apiECMAScript 2018colorsbootstrap cssfixed-widtherrorWeakMapsigtermbrowserlisttakefindLastIndexformatasciilogobjectrgb0ArrayBufferstreamduplexmobilebundlingpicomatchsymlinksmapreducewafreadablestatusisnegativeeventsauthenticationupcall-bindObject.definePropertytrimdirectoryrobusttrimEndArray.prototype.flatMapimportexportes-abstractdeepcopyawesomesaucelanguagemimetypescloudwatchlinkcontainsMapbyteObject.getPrototypeOffastcopyObjectreduxglacierurlfindupmergejavascriptdescriptorsettercodesi18nthrottletypesenvstylingsyntaxponyfilltapprogressconfigECMAScript 2021persistentpostcssbundlerECMAScript 2022windowsUint16ArrayconfigurabledebugspinnersbrowserquerycsseveryimmutablestartercharactersideutilitiesHyBiargstsstringpackage managerprettywaitmetadatasesenumerableflattenCSSStyleDeclarationcloudsearchmaprecursiveformgetterartdatees5watcharktypematchAllutil.inspecttoobjecthotimmerpreprocessorbluebirduuidvpctoSortedInt8Arrayindicatorutilxhrworkspace:*charactersES8statelesslimitintrinsicform-validationkeyseventEmitterxtermprotobrowserslistsharedcss lessESnextstyleguide_.extendspinnercommandrms3packagesasyncmomentcallbackes-shim APIPromisefast-deep-copyvalidtypescriptbatchhardlinkswalkdroptestecmascriptES2020whichtc39nopeflagslibphonenumberdebuggerredux-toolkitdataViewroute53valuesassignbindiebcryptcorssignalArraysuperstructhasOwnPropertyes7Array.prototype.filterarraybufferinparseiameslintconfigtypeReflect.getPrototypeOfdynamodbformattingbyteLengthenderlivestdlibestreeprocesscachestringifierio-tsJSONWebSocketInt16Arrayinternal slotchromiumcliserializeECMAScript 6visualtestingendpointbyteOffsethelpersfast-cloneassertswebencryptionast[[Prototype]]regexvalueamazonqueueMicrotaskwatchFilesinatraregexpdescriptorsarraysawaitelectrondependenciesfunctionzeroajaxtextrmdirterminalinternalcollection.es6@@toStringTagsetutilitySymbolRxJSlazymkdirsbannernodestructuredClonecallvariables in csspasswordReactiveXelbrm -rfreadablestreamcheckvalidationrapidtslibavarouteragentArray.prototype.containses-shimsdeterministices6snsmatchesformsECMAScript 2016ebsWebSocketsObject.valuestrimLeftStyleSheetcomparefastmodulestaskcryptwidthuninstallmochaprototypetoolsObject.assignES7karmaloadbalancinglesshookformcirculardeepcloudformationexpressoperating-systemcompilerfsequalitypromiseoffsetshrinkwrapexecarrayloadingmime-dbstatefullfileECMAScript 3weaksetjoilimitedgdprrdsdayjstoolkitString.prototype.trimzodassertionboundcommand-linecore-jsnpmglobECMAScript 2017Array.prototype.flatdatastructureerror-handlingcoretypeofhookspromisesawssameValueZerothroatgenericsreusewordwrapruntimerequestpropminimalefficientfull-widthdefinePropertypreserve-symlinksimportloggertesterjapanesedescriptionString.prototype.matchAlldeletestreams2serializermixinsbddauthsearchpackage.jsones2017extraObject.keyssafebufferunicodeArray.prototype.findLastIndexTypeScripttypesafebuffersschemeconcatparentstostringtagopenrequirevestprivate dataECMAScript 2023quotesequencesignalsdeepclonetoArrayreactresolveperformantregular expressionsshamArray.prototype.flattenslicecoercibleaccessibilitypropertyfindLastfullwidthRegExp#flagseslintpluginautoscalingreact-hooksvalidateshebangfpsec2groupredactSymbol.toStringTagpipeObject.isratelimitjsxfseventsinvariantworkflowremovetddless cssless.jsphonedeep-copyPushlruyupparentBigInt64ArrayfolderrestfulUint8Arrayqsaccessorframeworkcode pointsIteratorsymbolsTypeBoxtoStringTagcensorescapehas-ownshimwritefigletcurlworkermrupluginpnpm9handlersvariableses2015react-testing-libraryES2018Function.prototype.namegetOwnPropertyDescriptorless mixinsURLcolumngetparsinginstallemitlockfileprotobufclienteventDispatcherapolloRegExp.prototype.flagsa11yes8hashArrayBuffer.prototype.sliceautoprefixerjsonfunctionalsuperagenttrimRightproxynamerandomansiprefixsigintlastSet$.extendObservableURLSearchParamsgradients cssstreamsoptionl10nobjES5httpmacosbootstrap lesscomputed-typesswfjQuerysimpledbargparseArray.prototype.findLasttypeerrorfast-copyflatirqUint32Arrayfile systemregularES3Object.entriessharedarraybufferdiffdotenvES2021outputreducerECMAScript 5koreanlinuxjestfunctionsschemascheme-validationeslintCSSlookownidspeedregular expressioninspectsymlinkjsfind-upnegative zerocompile lessconsumeextendES2023typed array
1.0.0

1 year ago