application-prototype
Version:
Application builder - prototype
946 lines (852 loc) • 48.9 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>constructors/async.js - Application Prototype - Framework</title>
<meta name="description" content="Application Prototype Framework based on Module Pattern" />
<meta name="keywords" content="javascript, js, application-prototype, prototype" />
<meta name="keyword" content="javascript, js, application-prototype, prototype" />
<meta property="og:title" content="Application Prototype - Framework"/>
<meta property="og:type" content="website"/>
<meta property="og:image" content=""/>
<meta property="og:url" content="https://labs.sgapps.io/open-source/application-prototype"/>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav class="wrap">
<input type="text" id="nav-search" placeholder="Search" />
<h2><a href="index.html">Home</a></h2><h2><a href="https://labs.sgapps.io/open-source/application-prototype" target="_blank" class="menu-item" id="website_link" >Project Page ( Git Lab )</a></h2><h2><a href="http://gordienco.net/" target="_blank" class="menu-item" id="website_link" >About Me</a></h2><h2><a href="https://github.com/sergiu-gordienco/application-prototype" target="_blank" class="menu-item" id="github_link" >GitHub</a></h2><h3>Modules</h3><ul><li><a href="module-uriLoad.html">uriLoad</a><ul class='methods'><li data-type='method' style='display: none;'><a href="module-uriLoad.html#.link">link</a></li><li data-type='method' style='display: none;'><a href="module-uriLoad.html#.script">script</a></li></ul></li></ul><h3>Classes</h3><ul><li><a href="ApplicationPrototype.Builder.html">Builder</a><ul class='methods'><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#bind">bind</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#consoleOptions">consoleOptions</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#crudEvents">crudEvents</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#debugEnabled">debugEnabled</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#emit">emit</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#isBrowser">isBrowser</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#isNode">isNode</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#modulePath">modulePath</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#moduleRegister">moduleRegister</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#off">off</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#on">on</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#once">once</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#property">property</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#require">require</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#runModulesInFiles">runModulesInFiles</a></li></ul></li><li class="level-hide"><a href="ApplicationPrototype.Builder.Promise.html">Promise</a><ul class='methods'><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.Promise.html#.all">all</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.Promise.html#.race">race</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.Promise.html#.reject">reject</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.Promise.html#.resolve">resolve</a></li></ul></li><li><a href="ApplicationPrototype.Instance.html">Instance</a><ul class='methods'><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#bind">bind</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#crudEvents">crudEvents</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#emit">emit</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#off">off</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#on">on</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#once">once</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#property">property</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#property">property</a></li></ul></li><li><a href="async.Async.html">Async</a><ul class='methods'><li data-type='method' style='display: none;'><a href="async.Async.html#done">done</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#errors">errors</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#flush">flush</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#index">index</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#processing">processing</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#receive">receive</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#reserve">reserve</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#responses">responses</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#run">run</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#wait">wait</a></li></ul></li><li><a href="ExtensionsPrototype.slDOMSet.html">slDOMSet</a><ul class='methods'><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#add">add</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#attr">attr</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#attr">attr</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#attr">attr</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#attr">attr</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#config">config</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#config">config</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#each">each</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#env">env</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#eq">eq</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#filter">filter</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#find">find</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#get">get</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#get">get</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#map">map</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#set">set</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#set">set</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#unique">unique</a></li></ul></li><li><a href="JSTemplateComponent.html">JSTemplateComponent</a></li><li><a href="RequestModule.html">RequestModule</a><ul class='members'><li data-type='member' style='display: none;'><a href="RequestModule.html#.READY_STATE_DONE">READY_STATE_DONE</a></li><li data-type='member' style='display: none;'><a href="RequestModule.html#.READY_STATE_HEADERS_RECEIVED">READY_STATE_HEADERS_RECEIVED</a></li><li data-type='member' style='display: none;'><a href="RequestModule.html#.READY_STATE_LOADING">READY_STATE_LOADING</a></li><li data-type='member' style='display: none;'><a href="RequestModule.html#.READY_STATE_OPENED">READY_STATE_OPENED</a></li><li data-type='member' style='display: none;'><a href="RequestModule.html#.READY_STATE_UNSENT">READY_STATE_UNSENT</a></li></ul><ul class='methods'><li data-type='method' style='display: none;'><a href="RequestModule.html#.ParamsParser">ParamsParser</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#async">async</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#async">async</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#basicAuth">basicAuth</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#basicAuth">basicAuth</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#config">config</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#configurator">configurator</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#headers">headers</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#headers">headers</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#method">method</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#method">method</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#open">open</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#readyState">readyState</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#request">request</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#response">response</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#send">send</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#status">status</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#statusText">statusText</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#timeout">timeout</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#timeout">timeout</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#url">url</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#url">url</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#withCredentials">withCredentials</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#withCredentials">withCredentials</a></li></ul></li></ul><h3>Events</h3><ul><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__afterGet">__afterGet</a></li><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__afterGet::propName">__afterGet::propName</a></li><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__afterSet">__afterSet</a></li><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__afterSet::propName">__afterSet::propName</a></li><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__onGet">__onGet</a></li><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__onGet::propName">__onGet::propName</a></li><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__onSet">__onSet</a></li><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__onSet::propName">__onSet::propName</a></li></ul><h3>Interfaces</h3><ul><li><a href="ApplicationPrototype.html">ApplicationPrototype</a></li><li><a href="Array.html">Array</a><ul class='methods'><li data-type='method' style='display: none;'><a href="Array.html#__pointerFilter">__pointerFilter</a></li><li data-type='method' style='display: none;'><a href="Array.html#base64encode">base64encode</a></li><li data-type='method' style='display: none;'><a href="Array.html#bytesToHex">bytesToHex</a></li><li data-type='method' style='display: none;'><a href="Array.html#inArray">inArray</a></li><li data-type='method' style='display: none;'><a href="Array.html#indexOfSect">indexOfSect</a></li><li data-type='method' style='display: none;'><a href="Array.html#max">max</a></li><li data-type='method' style='display: none;'><a href="Array.html#min">min</a></li><li data-type='method' style='display: none;'><a href="Array.html#move">move</a></li><li data-type='method' style='display: none;'><a href="Array.html#resetArray">resetArray</a></li><li data-type='method' style='display: none;'><a href="Array.html#shuffle">shuffle</a></li><li data-type='method' style='display: none;'><a href="Array.html#split">split</a></li><li data-type='method' style='display: none;'><a href="Array.html#splitSect">splitSect</a></li><li data-type='method' style='display: none;'><a href="Array.html#toBinaryString">toBinaryString</a></li><li data-type='method' style='display: none;'><a href="Array.html#toBlob">toBlob</a></li><li data-type='method' style='display: none;'><a href="Array.html#toBytesBinary">toBytesBinary</a></li><li data-type='method' style='display: none;'><a href="Array.html#toBytesEscaped">toBytesEscaped</a></li><li data-type='method' style='display: none;'><a href="Array.html#toParamObj">toParamObj</a></li><li data-type='method' style='display: none;'><a href="Array.html#toStringUtf8">toStringUtf8</a></li><li data-type='method' style='display: none;'><a href="Array.html#unique">unique</a></li></ul></li><li><a href="ArrayBuffer.html">ArrayBuffer</a><ul class='methods'><li data-type='method' style='display: none;'><a href="ArrayBuffer.html#base64encode">base64encode</a></li><li data-type='method' style='display: none;'><a href="ArrayBuffer.html#toArray">toArray</a></li><li data-type='method' style='display: none;'><a href="ArrayBuffer.html#toBytes">toBytes</a></li><li data-type='method' style='display: none;'><a href="ArrayBuffer.html#toStringUtf8">toStringUtf8</a></li></ul></li><li><a href="async.html">async</a><ul class='methods'><li data-type='method' style='display: none;'><a href="async.html#.flow">flow</a></li><li data-type='method' style='display: none;'><a href="async.html#.flow_map">flow_map</a></li><li data-type='method' style='display: none;'><a href="async.html#.map">map</a></li><li data-type='method' style='display: none;'><a href="async.html#.waterfall">waterfall</a></li><li data-type='method' style='display: none;'><a href="async.html#.waterfall_map">waterfall_map</a></li></ul></li><li><a href="Blob.html">Blob</a><ul class='methods'><li data-type='method' style='display: none;'><a href="Blob.html#toArrayBuffer">toArrayBuffer</a></li><li data-type='method' style='display: none;'><a href="Blob.html#toURL">toURL</a></li></ul></li><li><a href="BrowserSessionModule.html">BrowserSessionModule</a><ul class='methods'><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.clear">clear</a></li><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.findItems">findItems</a></li><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.getItem">getItem</a></li><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.getItems">getItems</a></li><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.removeItem">removeItem</a></li><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.removeItems">removeItems</a></li><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.setItem">setItem</a></li><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.setItems">setItems</a></li></ul></li><li><a href="Buffer.html">Buffer</a><ul class='methods'><li data-type='method' style='display: none;'><a href="Buffer.html#base64encode">base64encode</a></li><li data-type='method' style='display: none;'><a href="Buffer.html#toArray">toArray</a></li><li data-type='method' style='display: none;'><a href="Buffer.html#toBytes">toBytes</a></li><li data-type='method' style='display: none;'><a href="Buffer.html#toStringUtf8">toStringUtf8</a></li></ul></li><li><a href="ExtensionsPrototype.html">ExtensionsPrototype</a><ul class='members'><li data-type='member' style='display: none;'><a href="ExtensionsPrototype.html#._">_</a></li><li data-type='member' style='display: none;'><a href="ExtensionsPrototype.html#.__">__</a></li><li data-type='member' style='display: none;'><a href="ExtensionsPrototype.html#.fn">fn</a></li><li data-type='member' style='display: none;'><a href="ExtensionsPrototype.html#.object">object</a></li><li data-type='member' style='display: none;'><a href="ExtensionsPrototype.html#.string">string</a></li><li data-type='member' style='display: none;'><a href="ExtensionsPrototype.html#.WindowExtend">WindowExtend</a></li></ul></li><li><a href="Function.html">Function</a><ul class='methods'><li data-type='method' style='display: none;'><a href="Function.html#runInWorker">runInWorker</a></li><li data-type='method' style='display: none;'><a href="Function.html#toWorker">toWorker</a></li><li data-type='method' style='display: none;'><a href="Function.html#toWorkerURL">toWorkerURL</a></li></ul></li><li><a href="HTMLElement.html">HTMLElement</a></li><li><a href="JSTemplate.html">JSTemplate</a><ul class='methods'><li data-type='method' style='display: none;'><a href="JSTemplate.html#.attrParser">attrParser</a></li><li data-type='method' style='display: none;'><a href="JSTemplate.html#.expressionBuilder">expressionBuilder</a></li><li data-type='method' style='display: none;'><a href="JSTemplate.html#.nodeParser">nodeParser</a></li><li data-type='method' style='display: none;'><a href="JSTemplate.html#.parseTextNodes">parseTextNodes</a></li><li data-type='method' style='display: none;'><a href="JSTemplate.html#.textParser">textParser</a></li></ul></li><li><a href="JSTemplateComponent.contextInstance.html">contextInstance</a><ul class='members'><li data-type='member' style='display: none;'><a href="JSTemplateComponent.contextInstance.html#.node">node</a></li><li data-type='member' style='display: none;'><a href="JSTemplateComponent.contextInstance.html#.references">references</a></li></ul><ul class='methods'><li data-type='method' style='display: none;'><a href="JSTemplateComponent.contextInstance.html#.redraw">redraw</a></li><li data-type='method' style='display: none;'><a href="JSTemplateComponent.contextInstance.html#.redrawForce">redrawForce</a></li></ul></li><li><a href="JSTemplateComponent.contextWithInstance.html">contextWithInstance</a><ul class='members'><li data-type='member' style='display: none;'><a href="JSTemplateComponent.contextWithInstance.html#.__instance">__instance</a></li><li data-type='member' style='display: none;'><a href="JSTemplateComponent.contextWithInstance.html#.__lifeCycle">__lifeCycle</a></li><li data-type='member' style='display: none;'><a href="JSTemplateComponent.contextWithInstance.html#.state">state</a></li></ul></li><li><a href="JSTemplateComponent.contextWithoutInstance.html">contextWithoutInstance</a><ul class='members'><li data-type='member' style='display: none;'><a href="JSTemplateComponent.contextWithoutInstance.html#.__lifeCycle">__lifeCycle</a></li><li data-type='member' style='display: none;'><a href="JSTemplateComponent.contextWithoutInstance.html#.state">state</a></li></ul></li><li><a href="String.html">String</a><ul class='methods'><li data-type='method' style='display: none;'><a href="String.html#add_Class">add_Class</a></li><li data-type='method' style='display: none;'><a href="String.html#add_Class">add_Class</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decode">base64decode</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decode">base64decode</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decodeBytes">base64decodeBytes</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decodeBytes">base64decodeBytes</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decodeBytesArray">base64decodeBytesArray</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decodeBytesArray">base64decodeBytesArray</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decodeClean">base64decodeClean</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decodeClean">base64decodeClean</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encode">base64encode</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encode">base64encode</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encodeBytes">base64encodeBytes</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encodeBytes">base64encodeBytes</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encodeBytesArray">base64encodeBytesArray</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encodeBytesArray">base64encodeBytesArray</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encodeClean">base64encodeClean</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encodeClean">base64encodeClean</a></li><li data-type='method' style='display: none;'><a href="String.html#buildQuery">buildQuery</a></li><li data-type='method' style='display: none;'><a href="String.html#buildQuery">buildQuery</a></li><li data-type='method' style='display: none;'><a href="String.html#buildSearchArray">buildSearchArray</a></li><li data-type='method' style='display: none;'><a href="String.html#buildSearchArray">buildSearchArray</a></li><li data-type='method' style='display: none;'><a href="String.html#cleanTags">cleanTags</a></li><li data-type='method' style='display: none;'><a href="String.html#cleanTags">cleanTags</a></li><li data-type='method' style='display: none;'><a href="String.html#decodeURI">decodeURI</a></li><li data-type='method' style='display: none;'><a href="String.html#decodeURI">decodeURI</a></li><li data-type='method' style='display: none;'><a href="String.html#decryptAes">decryptAes</a></li><li data-type='method' style='display: none;'><a href="String.html#decryptAes">decryptAes</a></li><li data-type='method' style='display: none;'><a href="String.html#decryptTea">decryptTea</a></li><li data-type='method' style='display: none;'><a href="String.html#decryptTea">decryptTea</a></li><li data-type='method' style='display: none;'><a href="String.html#del_Class">del_Class</a></li><li data-type='method' style='display: none;'><a href="String.html#del_Class">del_Class</a></li><li data-type='method' style='display: none;'><a href="String.html#encodeURI">encodeURI</a></li><li data-type='method' style='display: none;'><a href="String.html#encodeURI">encodeURI</a></li><li data-type='method' style='display: none;'><a href="String.html#encryptAes">encryptAes</a></li><li data-type='method' style='display: none;'><a href="String.html#encryptAes">encryptAes</a></li><li data-type='method' style='display: none;'><a href="String.html#encryptTea">encryptTea</a></li><li data-type='method' style='display: none;'><a href="String.html#encryptTea">encryptTea</a></li><li data-type='method' style='display: none;'><a href="String.html#escape">escape</a></li><li data-type='method' style='display: none;'><a href="String.html#escape">escape</a></li><li data-type='method' style='display: none;'><a href="String.html#escapeHex">escapeHex</a></li><li data-type='method' style='display: none;'><a href="String.html#escapeHex">escapeHex</a></li><li data-type='method' style='display: none;'><a href="String.html#fnd_Class">fnd_Class</a></li><li data-type='method' style='display: none;'><a href="String.html#fnd_Class">fnd_Class</a></li><li data-type='method' style='display: none;'><a href="String.html#fromHex">fromHex</a></li><li data-type='method' style='display: none;'><a href="String.html#fromHex">fromHex</a></li><li data-type='method' style='display: none;'><a href="String.html#fromHtml">fromHtml</a></li><li data-type='method' style='display: none;'><a href="String.html#fromHtml">fromHtml</a></li><li data-type='method' style='display: none;'><a href="String.html#lcfirst">lcfirst</a></li><li data-type='method' style='display: none;'><a href="String.html#lcfirst">lcfirst</a></li><li data-type='method' style='display: none;'><a href="String.html#markdown">markdown</a></li><li data-type='method' style='display: none;'><a href="String.html#match_str">match_str</a></li><li data-type='method' style='display: none;'><a href="String.html#match_str">match_str</a></li><li data-type='method' style='display: none;'><a href="String.html#md5">md5</a></li><li data-type='method' style='display: none;'><a href="String.html#md5">md5</a></li><li data-type='method' style='display: none;'><a href="String.html#parseUrl">parseUrl</a></li><li data-type='method' style='display: none;'><a href="String.html#parseUrl">parseUrl</a></li><li data-type='method' style='display: none;'><a href="String.html#parseUrlVars">parseUrlVars</a></li><li data-type='method' style='display: none;'><a href="String.html#sha1">sha1</a></li><li data-type='method' style='display: none;'><a href="String.html#sha1">sha1</a></li><li data-type='method' style='display: none;'><a href="String.html#sha256">sha256</a></li><li data-type='method' style='display: none;'><a href="String.html#sha256">sha256</a></li><li data-type='method' style='display: none;'><a href="String.html#subs">subs</a></li><li data-type='method' style='display: none;'><a href="String.html#subs">subs</a></li><li data-type='method' style='display: none;'><a href="String.html#subs">subs</a></li><li data-type='method' style='display: none;'><a href="String.html#swp_case">swp_case</a></li><li data-type='method' style='display: none;'><a href="String.html#swp_case">swp_case</a></li><li data-type='method' style='display: none;'><a href="String.html#toArrayBufferFromUtf8">toArrayBufferFromUtf8</a></li><li data-type='method' style='display: none;'><a href="String.html#toArrayBufferFromUtf8">toArrayBufferFromUtf8</a></li><li data-type='method' style='display: none;'><a href="String.html#toHex">toHex</a></li><li data-type='method' style='display: none;'><a href="String.html#toHex">toHex</a></li><li data-type='method' style='display: none;'><a href="String.html#toHtml">toHtml</a></li><li data-type='method' style='display: none;'><a href="String.html#toHtml">toHtml</a></li><li data-type='method' style='display: none;'><a href="String.html#toHtmlSimple">toHtmlSimple</a></li><li data-type='method' style='display: none;'><a href="String.html#toHtmlSimple">toHtmlSimple</a></li><li data-type='method' style='display: none;'><a href="String.html#toRegexp">toRegexp</a></li><li data-type='method' style='display: none;'><a href="String.html#toRegexp">toRegexp</a></li><li data-type='method' style='display: none;'><a href="String.html#ucfirst">ucfirst</a></li><li data-type='method' style='display: none;'><a href="String.html#ucfirst">ucfirst</a></li><li data-type='method' style='display: none;'><a href="String.html#unescape">unescape</a></li><li data-type='method' style='display: none;'><a href="String.html#unescape">unescape</a></li><li data-type='method' style='display: none;'><a href="String.html#unicode">unicode</a></li><li data-type='method' style='display: none;'><a href="String.html#unicode">unicode</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8">utf8</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8">utf8</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8decode">utf8decode</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8decode">utf8decode</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8encode">utf8encode</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8encode">utf8encode</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8need">utf8need</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8need">utf8need</a></li></ul></li><li></li></ul><h3>Global</h3><ul><li><a href="global.html#ApplicationBuilderConstructor">ApplicationBuilderConstructor</a></li><li><a href="global.html#ApplicationBuilderExports">ApplicationBuilderExports</a></li><li><a href="global.html#ApplicationPrototypeConstructor">ApplicationPrototypeConstructor</a></li><li><a href="global.html#NodeInterface">NodeInterface</a></li><li><a href="global.html#RequestModuleConstructor">RequestModuleConstructor</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">constructors/async.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* @callback AsyncConstructor
* @memberof async
* @returns {async.Async}
*/
/**
* Module used processing data asynchronous
* @example
* Application.require('async').then(function (asyncOperations) {
* // @TODO
* }, console.error);
* @interface async
* @returns {async.AsyncConstructor}
* @see async.Async
*/
/**
* @class
* @name Async
* @memberof async
*/
var async = function () {
var life = 0;
var waited = 0;
var received = 0;
var responsesId = [];
var responses = {};
var context = {};
var app = new ApplicationPrototype();
/**
* return unique index identifier for an operation
* @method index
* @memberof async.Async#
* @returns {string}
*/
app.bind("index", ((function () {
var index = 0;
return function () {
return life + '::' + ( ++index );
};
})()), '');
/**
* method used for return result for an operation,
* returns `true` if value was accepted.
* if operation already obtained a value
* then value is not accepted and it returns `false`
* @method receive
* @memberof async.Async#
* @param {string} id obtained from {@link async.Async#index}
* @param {any} args
* @returns {boolean}
*/
app.bind("receive", function (id, args) {
if (id) {
if (id.indexOf(life+'::') !== 0) {
return false;
}
responses[id] = args;
}
received += 1;
if (received == waited) {
app.emit("done");
}
return true;
}, 'on af st');
/**
* require to wait an additional operation
* @method wait
* @memberof async.Async#
*/
app.bind("wait", function () {
waited += 1;
}, 'on af st');
/**
* require to reserve index {@link async.Async#index} for an additional operation
* @method reserve
* @memberof async.Async#
* @returns {string}
*/
app.bind("reserve", function () {
waited += 1;
return app.index();
}, 'on af st');
/**
* require to run an operation
* @method run
* @memberof async.Async#
* @param {function():void} func function that should be executed
* @param {any[]} args
* @param {object} context
* @returns {string}
*/
app.bind("run", function (func, args, context) {
var id = app.index();
responsesId.push(id);
waited+=1;
func.apply(context, args);
return id;
}, 'on af st');
/**
* reset operation processing
* @method flush
* @memberof async.Async#
*/
app.bind("flush", function () {
life += 1;
responses = {};
responsesId = [];
received = 0;
waited = 0;
}, 'on af st');
/**
* return how many operations are processing right now
* @method processing
* @memberof async.Async#
* @returns {number}
*/
app.bind('processing', function () {
return ( waited - received );
}, '');
/**
* return operations' responses
* @method responses
* @memberof async.Async#
* @param {boolean} [returnUnknownResponses=false]
* @returns {any[][]}
*/
app.bind('responses', function (id) {
if (id === true) {
return responsesId.map(function (v) {
return (v in responses ? responses[v] : undefined);
});
}
return responses;
});
/**
* return all errors found in responses
* @method errors
* @memberof async.Async#
* @returns {Error[]}
*/
app.bind('errors', function () {
var errs = [];
responsesId.forEach(function (id) {
var r = responses[id];
if (r instanceof Error) {
errs.push(r);
} else {
var i;
for (i=0;i<r.length;i++) {
if (r[i] instanceof Error) {
errs.push(r[i]);
}
}
}
});
return errs;
});
/**
* register a callback to be called when processing is done
* @method done
* @memberof async.Async#
* @param {function():void} cb
*/
app.bind('done', function (cb) {
if (typeof(cb) === "function") {
app.on('done', cb);
if (received === waited && received) {
cb.apply(app, []);
}
}
});
return app;
};
/**
* @typedef {object} Operation
* @memberof async.Async
* @property {async.Async.OperationCallback} [0]
* @property {async.Async.OperationArgs} [1]
* @property {async.Async.OperationContext} [2]
* @property {async.Async.OperationCallbackIndex} [3]
*/
/**
* a function that represents the operation itself, it have as argument `next` callback, by default it is first.
* @typedef {Function} OperationCallback
* @memberof async.Async
*/
/**
* list if arguments passed to `OperationCallback`.
* @typedef {any[]} OperationArgs
* @memberof async.Async
*/
/**
* context that should be used in `OperationCallback`. Default value is `{}`.
* @typedef {object} OperationContext
* @memberof async.Async
*/
/**
* index of `next()` callback in list of `OperationCallback`'s arguments. Default value is `0`.
* @typedef {number} OperationCallbackIndex
* @memberof async.Async
*/
/**
* @typedef {async.Async.Operation[]} Operations
* @memberof async.Async
*/
/**
* @callback async.processCallback
* @param {function(Error?): void} next
* @param {any} item
* @param {number} index
* @param {any[]} items
*/
/**
* @callback async.doneCallback
* @this async.Async
*/
/**
* @method flow
* @memberof async.
* @param {async.Async.Operations} operations
* @param {async.doneCallback} cb
* @param {number} [timeout=0] timeout between operations
* @returns {async.Async}
*/
async.flow = function (operations, cb, timeout) {
if (typeof(operations) !== "undefined" && Array.isArray(operations)) {
var app = new async();
app.done(cb);
var c = {};
timeout = timeout || 0;
var i = 0;
if (operations.length === 0) {
app.emit('done');
}
var tick = function () {
if ( i < operations.length) {
var op = operations[i++];
if (op) {
var ar = op[1] || [];
var ai = op[3] || 0;
var id = app.reserve();
ar[ai] = function () {
app.receive(id, arguments);
};
var err;
setTimeout(function () {
try {
op[0].apply(op[2] || c, ar);
} catch (err) {
app.receive(id, err);
app.emit('error', [err]);
}
}, timeout);
}
}
};
app.on('onReceive', function () {
// console.log("tick");
tick();
});
tick();
return app;
}
return;
};
/**
* @method waterfall
* @memberof async.
* @param {async.Async.Operations} operations
* @param {async.doneCallback} cb
* @param {number} [parallel=27] number of operations that can be done in parallel
* @param {number} [timeout=0] timeout between operations
* @returns {async.Async}
*/
async.waterfall = function (ops, cb, parallel, timeout) {
if (typeof(ops) !== "undefined" && Array.isArray(ops)) {
var app = new async();
app.done(cb);
var c = {};
timeout = timeout || 0;
if (typeof(parallel) !== "number") {
parallel = 27;
}
var i = 0;
if (ops.length === 0) {
app.emit('done');
}
var tick = function () {
if ( i < ops.length) {
var op = ops[i++];
if (op) {
var ar = op[1] || [];
var ai = op[3] || 0;
var id = app.reserve();
ar[ai] = function () {
app.receive(id, arguments);
};
var err;
setTimeout(function () {
try {
op[0].apply(op[2] || c, ar);
} catch (err) {
app.receive(id, err);
app.emit('error', [err]);
}
}, timeout);
}
return true;
}
return false;
};
app.on('onReceive', function () {
// console.log("tick");
while (( parallel === 0 || parallel > app.processing()) && tick()) {
// true;
}
});
tick();
return app;
}
return;
};
/**
* @method map
* @memberof async.
* @param {any[]} operations
* @param {async.processCallback}
* @param {async.doneCallback} cb
* @param {number} [timeout=0] timeout between operations
* @returns {async.Async}
*/
/**
* @method flow_map
* @memberof async.
* @param {any[]} operations
* @param {async.processCallback}
* @param {async.doneCallback} cb
* @param {number} [timeout=0] timeout between operations
* @returns {async.Async}
*/
async.map = async.flow.map = function (ops, ev, cb, timeout) {
if (typeof(ops) !== "undefined" && Array.isArray(ops)) {
var app = new async();
var c = {};
timeout = timeout || 0;
var i = 0;
var ret = [];
app.done(function () {
cb.apply(app,[ret]);
});
if (ops.length) {
ret[ops.length - 1] = undefined;
} else {
app.emit('done');
}
var tick = function () {
if ( i < ops.length) {
var op = ops[i++];
var id = app.reserve();
var ri = i-1;
var rr = function (v, err) {
if (err) {
app.receive(id, err);
app.emit('error', [err]);
} else {
ret[ri] = v;
app.receive();
}
};
var err;
setTimeout(function () {
try {
ev.apply(ops, [rr, op, ri, ops]);
} catch (err) {
app.receive(id, err);
app.emit('error', [err]);
}
}, timeout);
}
};
app.on('onReceive', function () {
tick();
});
tick();
return app;
}
return;
};
/**
* @method waterfall_map
* @memberof async.
* @param {any[]} operations
* @param {async.processCallback}
* @param {async.doneCallback} cb
* @param {number} [parallel=27] number of operations that can be done in parallel
* @param {number} [timeout=0] timeout between operations
* @returns {async.Async}
*/
async.waterfall.map = function (ops, ev, cb, parallel, timeout) {
if (typeof(ops) !== "undefined" && Array.isArray(ops)) {
var app = new async();
var c = {};
timeout = timeout || 0;
if (typeof(parallel) !== "number") {
parallel = 27;
}
var i = 0;
var ret = [];
app.done(function () {
cb.apply(app,[ret]);
});
if (ops.length) {
ret[ops.length - 1] = undefined;
} else {
app.emit('done');
}
var tick = function () {
if ( i < ops.length) {
var op = ops[i++];
var id = app.reserve();
var ri = i-1;
var rr = function (v, err) {
if (err) {
app.receive(id, err);
app.emit('error', [err]);
} else {
ret[ri] = v;
app.receive();
}
};
var err;
setTimeout(function () {
try {
ev.apply(ops, [rr, op, ri, ops]);
} catch (err) {
app.receive(id, err);
app.emit('error', [err]);
}
}, timeout);
}
};
app.on('onReceive', function () {
while (( parallel === 0 || parallel > app.processing()) && tick()) {
// true;
}
});
tick();
return app;
}
return;
};
async.filter = async.flow.filter = function (ops, ev, cb, timeout) {
if (typeof(ops) !== "undefined" && Array.isArray(ops)) {
var app = new async();
var c = {};
timeout = timeout || 0;
var i = 0;
var ret = [];
app.done(function () {
cb.apply(app,[ret]);
});
if (ops.length) {
} else {
app.emit('done');
}
var tick = function () {
if ( i < ops.length) {
var op = ops[i++];
var id = app.reserve();
var ri = i-1;
var rr = function (v, err) {
if (err) {
app.receive(id, err);
app.emit('error', [err]);
} else {
if (v) ret.push(op);
app.receive();
}
};
var err;
setTimeout(function () {
try {
ev.apply(ops, [rr, op, ri, ops]);
} catch (err) {
app.receive(id, err);
app.emit('error', [err]);
}
}, timeout);
}
};
app.on('onReceive', function () {
tick();
});
tick();
return app;
}
return;
};
async.waterfall.filter = function (ops, ev, cb, parralel, timeout) {
if (typeof(ops) !== "undefined" && Array.isArray(ops)) {
var app = new async();
var c = {};
timeout = timeout || 0;
if (typeof(parralel) !== "number") {
parralel = 27;
}
var i = 0;
var ret = [];
app.done(function () {
cb.apply(app,[ret]);
});
if (ops.length) {
} else {
app.emit('done');
}
var tick = function () {
if ( i < ops.length) {
var op = ops[i++];
var id = app.reserve();
var ri = i-1;
var rr = function (v, err) {
if (err) {
app.receive(id, err);
app.emit('error', [err]);
} else {
if (v) ret.push(op);
app.receive();
}
};
var err;
setTimeout(function () {
try {
ev.apply(ops, [rr, op, ri, ops]);
} catch (err) {
app.receive(id, err);
app.emit('error', [err]);
}
}, timeout);
return true;
}
return false;
};
app.on('onReceive', function () {
// debugger;
while (( parralel === 0 || parralel > app.processing()) && tick()) {
// true;
}
});
tick();
return app;
}
return;
};
async.forEach = async.flow.forEach = function (ops, ev, cb, timeout) {
if (typeof(ops) !== "undefined" && Array.isArray(ops)) {
var app = new async();
var c = {};
timeout = timeout || 0;
var i = 0;
app.done(function () {
cb.apply(app,[ops]);
});
if (ops.length) {
} else {
app.emit('done');
}
var tick = function () {
if ( i < ops.length) {
var op = ops[i++];
var id = app.reserve();
var ri = i-1;
var rr = function (err) {
if (err) {
app.receive(id, err);
app.emit('error', [err]);
} else {
app.receive();
}
};
var err;
setTimeout(function () {
try {
ev.apply(ops, [rr, op, ri, ops]);
} catch (err) {
app.receive(id, err);
app.emit('error', [err]);
}
}, timeout);
return true;
}
return false;
};
app.on('onReceive', function () {
tick();
});
tick();
return app;
}
return;
};
async.waterfall.forEach = function (ops, ev, cb, parralel, timeout) {
if (typeof(ops) !== "undefined" && Array.isArray(ops)) {
var app = new async();
var c = {};
timeout = timeout || 0;
if (typeof(parralel) !== "number") {
parralel = 27;
}
var i = 0;
app.done(function () {
cb.apply(app,[ops]);
});
if (ops.length) {
} else {
app.emit('done');
}
var tick = function () {
if ( i < ops.length) {
var op = ops[i++];
var id = app.reserve();
var ri = i-1;
var rr = function (err) {
if (err) {
app.receive(id, err);
app.emit('error', [err]);
} else {
app.receive();
}
};
var err;
setTimeout(function () {
try {
ev.apply(ops, [rr, op, ri, ops]);
} catch (err) {
app.receive(id, err);
app.emit('error', [err]);
}
}, timeout);
return true;
}
return false;
};
app.on('onReceive', function () {
while (( parralel === 0 || parralel > app.processing()) && tick()) {
// true;
}
});
tick();
return app;
}
return;
};
async.test = {};
async.test.flow = function (n) {
console.clear();
global.require('async', function (async) {
if (typeof(n) !== "number") n = 1000;
var ops = [];
var i = 0;
while (i++ < n) {
ops.push([(function (k) {
return function (cb) {
cb(k);
};
})(i + 0)]);
}
console.log(ops.length);
var t0 = new Date().valueOf();
var a1 = async.flow(ops, function () {
console.log((new Date().valueOf() - t0)/(n * 1000));
});
var k=0;
a1.on('onError', function (err) {
console.error(err);
});
a1.on('onReceive', function () {
console.log(k++);
});
window.a1 = a1;
});
};
async.test.waterfall = function (n) {
console.clear();
global.require('async', function (async) {
if (typeof(n) !== "number") n = 1000;
var ops = [];
var i = 0;
while (i++ < n) {
ops.push([(function (k) {
return function (cb) {
cb(k);
};
})(i + 0)]);
}
console.log(ops.length);
var t0 = new Date().valueOf();
var a1 = async.waterfall(ops, function () {
console.log((new Date().valueOf() - t0)/(n * 1000));
}, 69);
var k=0;
a1.on('onError', function (err) {
console.error(err);
});
a1.on('onReceive', function () {
console.log(k++);
});
window.a1 = a1;
});
};
async.test.map = async.test.flow.map = function (n) {
console.clear();
global.require('async', function (async) {
if (typeof(n) !== "number") n = 1000;
var b = [];
if (n)
b[n - 1] = undefined;
async.flow.map(b, function (cb, v, i, arr) {
console.log(i);
cb(Math.floor(Math.random() * 1000));
}, function (r) {
console.log("DONE", r);
});
});
};
async.test.waterfall.map = function (n) {
console.clear();
global.require('async', function (async) {
if (typeof(n) !== "number") n = 1000;
var b = [];
if (n)
b[n - 1] = undefined;
async.waterfall.map(b, function (cb, v, i, arr) {
console.log(i);
cb(Math.floor(Math.random() * 1000));
}, function (r) {
console.log("DONE", r);
});
});
};
async.test.filter = async.test.flow.filter = function (n) {
console.clear();
global.require('async', function (async) {
if (typeof(n) !== "number") n = 1000;
var b = [];
if (n)
b[n - 1] = undefined;
async.flow.filter(b, function (cb, v, i, arr) {
console.log(i);
cb(Math.random() > 0.5);
}, function (r) {
console.log("DONE ", r.length);
});
});
};
async.test.waterfall.filter = function (n) {
console.clear();
global.require('async', function (async) {
if (typeof(n) !== "number") n = 1000;
var b = [];
if (n)
b[n - 1] = undefined;
async.waterfall.filter(b, function (cb, v, i, arr) {
console.log(i);
cb(Math.random() > 0.5);
}, function (r) {
console.log("DONE ", r.length);
});
});
};
async.test.forEach = async.test.flow.forEach = function (n) {
console.clear();
global.require('async', function (async) {
if (typeof(n) !== "number") n = 1000;
var b = [];
if (n)
b[n - 1] = undefined;
async.flow.forEach(b, function (cb, v, i, arr) {
console.log(i);
cb();
}, function (r) {
console.log("DONE ", r.length);
});
});
};
async.test.waterfall.forEach = function (n) {
console.clear();
global.require('async', function (async) {
if (typeof(n) !== "number") n = 1000;
var b = [];
if (n)
b[n - 1] = undefined;
async.waterfall.forEach(b, function (cb, v, i, arr) {
console.log(i);
cb();
}, function (r) {
console.log("DONE ", r.length);
});
});
};
module.exports = async;
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/search.js" defer></script>
<script src="scripts/collapse.js" defer></script>
<script src="https://sgapps.io/components/sgapps-labs-examples/toolbar/loader.js"></script>
</body>
</html>