<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Suguru Motegi on Medium]]></title>
        <description><![CDATA[Stories by Suguru Motegi on Medium]]></description>
        <link>https://medium.com/@suguru.motegi?source=rss-dee8a5fad519------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jiSRvCx7_ohQ1T9N8nDiHQ.jpeg</url>
            <title>Stories by Suguru Motegi on Medium</title>
            <link>https://medium.com/@suguru.motegi?source=rss-dee8a5fad519------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 08:15:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@suguru.motegi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to use Lo-Dash functions with Async/Await]]></title>
            <link>https://medium.com/hackernoon/how-to-use-lo-dash-functions-with-async-await-b0be7709534c?source=rss-dee8a5fad519------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0be7709534c</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[async]]></category>
            <category><![CDATA[asyncawait]]></category>
            <dc:creator><![CDATA[Suguru Motegi]]></dc:creator>
            <pubDate>Mon, 02 Oct 2017 15:51:20 GMT</pubDate>
            <atom:updated>2017-10-02T15:51:20.442Z</atom:updated>
            <content:encoded><![CDATA[<p>Lo-Dash is a really cool and useful library. If we are able to use the functions with Async/Await, the JavaScript life will be more comfortable.<br>I would like to write the same as Lo-Dash function’s way as much as possible. Because if we already know how to use Lo-Dash, we don’t need to learn new functions. The example code is written as below.</p><pre>// example 1<br>const array = [1, 2, 3];<br>const result = _.map(array, syncFunc);</pre><pre>// ↓ async/await</pre><pre>const result = await _.map(array, asyncFunc);</pre><pre>function syncFunc(n) {<br>  return n * 2;<br>}<br>function asyncFunc(n) {<br>  return new Promise(resolve =&gt; setTimeout(resolve, 10, n * 2));<br>}</pre><p>The _.chain makes our code clean, we would also like to use it.</p><pre>// example 2<br>const array = [1, 2, 3];<br>const result = _.chain(array)<br>  .map(syncFunc)<br>  .sum()<br>  .value();</pre><pre>// ↓ async/await</pre><pre>const result = await _.chain(array)<br>  .map(asyncFunc)<br>  .sum()<br>  .value();</pre><h3>Convert Lo-Dash functions to asynchronous functions</h3><p>Aigle library which I have developed has the mixin function. It converts Lo-Dash functions to asynchronous functions and assigns them into Aigle. The usage is as below.</p><pre>const _ = require(&#39;lodash&#39;);<br>const Aigle = require(&#39;aigle&#39;);</pre><pre>Aigle.mixin(_);</pre><pre>// example 1<br>const array = [1, 2, 3];<br>const result = await Aigle.map(array, asyncFunc);</pre><pre>// example 2<br>const result = await Aigle.chain(array)<br>  .map(asyncFunc)<br>  .sum()<br>  .value();</pre><pre>// or</pre><pre>const result = await Aigle.resolve(array)<br>  .map(asyncFunc)<br>  .sum();</pre><p>You will be able to use the Lo-Dash functions asynchronously. Furthermore, Aigle already has many functions which have the same functionality as Lo-Dash functions, these functions won’t be converted because they are already optimized.</p><h3>Conclusion</h3><p>Aigle will make your code clean the same as Lo-Dash. If you are interested in Aigle, I would love you to read the following articles. Let’s enjoy Async/Await using Aigle.</p><h4>Reference</h4><ul><li><a href="https://github.com/suguru03/aigle">Aigle</a></li><li><a href="https://github.com/lodash/lodash">Lo-Dash</a></li><li><a href="https://hackernoon.com/how-to-make-the-fastest-promise-library-f632fd69f3cb">How to make the fastest Promise library</a></li><li><a href="https://hackernoon.com/aigle-vs-bluebird-5ed3becb4c4c">Aigle vs Bluebird</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0be7709534c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/how-to-use-lo-dash-functions-with-async-await-b0be7709534c">How to use Lo-Dash functions with Async/Await</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Aigle vs Bluebird]]></title>
            <link>https://medium.com/hackernoon/aigle-vs-bluebird-5ed3becb4c4c?source=rss-dee8a5fad519------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ed3becb4c4c</guid>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[aigle]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Suguru Motegi]]></dc:creator>
            <pubDate>Thu, 11 May 2017 06:00:08 GMT</pubDate>
            <atom:updated>2017-07-19T15:13:19.715Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ATqFLYyVcMc1akgPQMz6Cg.png" /><figcaption>bench doxbee</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_pdSRN3WWeX5e0DaadgXZw.png" /><figcaption>bench parallel</figcaption></figure><p><a href="https://github.com/suguru03/aigle">Aigle</a> is an ideal promise library that I created to improve inefficiencies that I noticed when using other promise libraries like Bluebird. On top of being an impressive benchmark exercise, it is a production-ready library that implements the Promise A+ standard.</p><h3>Benchmark</h3><p><a href="https://github.com/suguru03/bluebird/tree/aigle/benchmark">The above benchmark exercises</a> indicates that Aigle is faster than Bluebird. This was achieved by avoiding unnecessary memory allocation and function calls. For instance, Aigle is able to optimize it’s dependencies while Bluebird’s performance is affected if it’s dependencies use different versions of it. For more information on how Aigle is faster than Bluebird, I would encourage you to read <a href="https://hackernoon.com/how-to-make-the-fastest-promise-library-f632fd69f3cb">my article</a> on it.</p><h3>Functions</h3><p>Aigle makes your code less verbose and contains many functions similar to <a href="https://github.com/lodash/lodash">Lodash</a> and <a href="https://github.com/caolan/async">Async</a>. As a result, you would be able to code faster and have a much easier time maintaining code.</p><h4>Aigle.map vs Bluebird.map</h4><p>Compared to Bluebird.map, Aigle.map is 1.5x faster and also supports an object as a first argument unlike Bluebird.map.</p><pre>const object = {<br>  a: 1,<br>  b: 2,<br>  c: 3<br>};<br>Blubird.map(Object.keys(object), key =&gt; {<br>  const value = object[key];<br>  ...<br>});<br>Aigle.map(object, (value, key) =&gt; { ... });</pre><p>If you want to use concurrency, Aigle has Aigle.mapLimit which is similar to Async.mapLimit.</p><pre>const array = [1, 2, 3, 4, 5];<br>Bluebird.map(array, value =&gt; {<br>  console.log(value); // 1, 2, 5, 4, 3 the order is not ensured<br>  return Bluebird.delay(10);<br>}, { concurrency: 2 });</pre><pre>Aigle.mapLimit(array, 2, value =&gt; {<br>  console.log(value); // 1, 2, 3, 4, 5 the order is ensured<br>  return Aigle.delay(10);<br>});</pre><pre>// you could use default limit, the limit is 8<br>Aigle.mapLimit(array, value =&gt; {<br>  console.log(value); // 1, 2, 3, 4, 5<br>  return Aigle.delay(10);<br>});</pre><p>In addition, Aigle supports shorthand notation similar to Lodash for cleaner code.</p><pre>const array = [{ name: &#39;barney&#39; }, { name: &#39;fred&#39; }];<br>Aigle.resolve(array)<br>  .map(&#39;name&#39;) // the function is called asynchronously<br>  .then(names =&gt; console.log(names)); // [&#39;barney&#39;, &#39;fred&#39;]</pre><h4>Aigle.mapValues</h4><p>The function is similar to Async.mapValues and Lodash.mapValues. It is also similar to Aigle.map, but it returns an object instead. Below is a code comparision between Aigle and Bluebird.</p><pre>const object = { a: 1, b: 2, c: 3 };<br>const iterator = value =&gt; Promise.resolve(value * 2);</pre><pre>// Bluebird<br>const result = {};<br>Bluebird.each(Object.keys(object), key =&gt; {<br>  const value = object[key];<br>  return iterator(value)<br>    .then(val =&gt; {<br>      result[key] = val;<br>    });<br>}).then(() =&gt; console.log(result)); // { a: 2, b: 4, c: 6 }</pre><pre>// Aigle<br>Aigle.mapValues(object, iterator)<br>  .then(result =&gt; console.log(result)); // { a: 2, b: 4, c: 6 }</pre><h3>Aigle.times</h3><p>The function is similar to Async.times and Lodash.times. It calls an iterator specified times.</p><pre>const n = 10;<br>const iterator = value =&gt; Promise.resolve(value * 2);</pre><pre>// Bluebird<br>const times = [];<br>for (let i = 0; i &lt; n; i++) {<br>  times.push(i);<br>}<br>Bluebird.map(times, iterator)<br>  .then(result =&gt; console.log(result)); // [0, 2, 4, ..., 18]</pre><pre>// Aigle<br>Aigle.times(n, iterator)<br>  .then(result =&gt; console.log(result)); // [0, 2, 4, ..., 18]</pre><h3>Conclusion</h3><p>Aigle is a promise library that provides safer, less verbose, and maintainable code that boasts impressive benchmarks. The documented examples above are only a subset of Aigle&#39;s functions. If you are already familiar with Lodash or Async, you will be able to easily transition into writing even more readable code with Aigle. With that said, let’s enjoy writing faster and more efficient Javascript using Aigle.</p><h3>Reference</h3><ul><li><a href="https://github.com/suguru03/aigle">Aigle</a></li><li><a href="https://github.com/petkaantonov/bluebird">Bluebird</a></li></ul><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ed3becb4c4c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/aigle-vs-bluebird-5ed3becb4c4c">Aigle vs Bluebird</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make the fastest Promise library]]></title>
            <link>https://medium.com/hackernoon/how-to-make-the-fastest-promise-library-f632fd69f3cb?source=rss-dee8a5fad519------2</link>
            <guid isPermaLink="false">https://medium.com/p/f632fd69f3cb</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[aigle]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Suguru Motegi]]></dc:creator>
            <pubDate>Mon, 03 Apr 2017 15:33:03 GMT</pubDate>
            <atom:updated>2017-07-18T21:52:26.887Z</atom:updated>
            <content:encoded><![CDATA[<p>I have developed <a href="https://github.com/suguru03/aigle">Aigle</a> which is a fast Promise library. It is inspired by<a href="https://github.com/petkaantonov/bluebird">Bluebir</a>d. The library is not only a <a href="https://github.com/suguru03/aigle/tree/master/benchmark#benchmark">benchmark</a> exercise but a production-ready library that implements the Promise A+ standard, and does so faster than Bluebird.</p><h3><strong>What are Promises?</strong></h3><p>Before explaining it, I would like to give basic information about Promises. A Promise can have three states: pending, fulfilled and rejected. Once the state goes to another state from pending, the state cannot change again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*g1EZpcctuSoa6Jcwp68SUQ.png" /><figcaption>Promise states (quote: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">MDN</a>)</figcaption></figure><p>Besides, Promises must always resolve asynchronously, this is one of the most important things.</p><pre><strong>new</strong> Promise(resolve =&gt; resolve(1)) // synchronously<br>  .then(num =&gt; {<br>    // called asynchronously<br>  });</pre><h3>Best practices for high-performance libraries</h3><p>When I develop libraries, I always follow these three principles.</p><ul><li>Avoid creating unnecessary variables, functions and instances</li><li>Avoid executing unnecessary functions</li><li>Deal with asynchronous function smartly</li></ul><h4>Avoid creating unnecessary variables, functions and instances</h4><p>Following this principle helps avoiding unnecessary memory allocations. For example,</p><pre><strong>function</strong> sum(array) {<br>  <strong>return</strong> array.reduce(<strong>function</strong> iterator(result, num) {<br>    <strong>return</strong> result <strong>+</strong> num;<br>  });<br>}<br><br>sum([1, 2, 3]); <em>// 6</em></pre><p>When sum is called, the iterator function is always created. It is one of unnecessary memory allocations. The code is rewritten to follow next example.</p><pre><strong>function</strong> iterator(result, num) {<br>  <strong>return</strong> result <strong>+</strong> num;<br>}<br><br><strong>function</strong> sum(array) {<br>  <strong>return</strong> array.reduce(iterator);<br>}<br><br>sum([1, 2, 3]); <em>// 6</em></pre><p>The code avoids making unnecessary functions.</p><p>Next is another extra example of memory allocation.</p><pre><strong>function</strong> get(type) {<br>  <strong>const</strong> array <strong>=</strong> [];<br>  <strong>const</strong> object <strong>=</strong> {};<br>  <strong>const</strong> number <strong>=</strong> 0;<br>  <strong>const</strong> string <strong>=</strong> &#39;&#39;;<br>  <strong>switch</strong> (type) {<br>  <strong>case</strong> &#39;array&#39;<strong>:</strong><br>    <strong>return</strong> array;<br>  <strong>case</strong> &#39;object&#39;<strong>:</strong><br>    <strong>return</strong> object;<br>  <strong>case</strong> &#39;number&#39;<strong>:</strong><br>    <strong>return</strong> number;<br>  <strong>case</strong> &#39;string&#39;<strong>:</strong><br>    <strong>return</strong> string;<br>  }<br>}<br>get(&#39;string&#39;);</pre><p>In this case, string is the only required variable. array, object and number are unnecessary. The code is rewritten as below,</p><pre><strong>function</strong> get(type) {<br>  <strong>switch</strong> (type) {<br>  <strong>case</strong> &#39;array&#39;<strong>:</strong><br>    <strong>return</strong> [];<br>  <strong>case</strong> &#39;object&#39;<strong>:</strong><br>    <strong>return</strong> {};<br>  <strong>case</strong> &#39;number&#39;<strong>:</strong><br>    <strong>return</strong> 0;<br>  <strong>case</strong> &#39;string&#39;<strong>:</strong><br>    <strong>return</strong> &#39;&#39;;<br>  }<br>}<br>get(&#39;string&#39;);</pre><p>There is not a big difference between the examples, but if instances or functions are created in the function, it would make big difference.</p><h4>Avoid executing unnecessary functions</h4><p>For example, when creating APIs, it is necessary to check the request parameters.</p><pre><strong>function</strong> api(req, res) {<br>  <strong>const</strong> { id } <strong>=</strong> req.body;<br>  <strong>if</strong> (<strong>!</strong>isNumber(id)) {<br>     <strong>return</strong> res.sendStatus(400);<br>  }<br>  innerFunc(id)<br>    .then(...)<br>    .<strong>catch</strong>(...)<br>}<br><br><strong>function</strong> isNumber(id) {<br>  <strong>return</strong> <strong>typeof</strong> id <strong>===</strong> &#39;number&#39;;<br>}<br><br><strong>function</strong> innerFunc(id) {<br>  <strong>if</strong> (<strong>!</strong>isNumber(id)) {<br>    <strong>return</strong> Promise.reject(<strong>new</strong> Error(&#39;error&#39;));<br>  }<br>  ...<br>}</pre><p>When implementing APIs, it is preferable to check the arguments in inner functions because the function might be called from other functions. However, when implementing libraries, the function doesn’t need to check the arguments. Before executing inner functions, the arguments are already checked, so it isn’t necessary to check them again in inner functions.</p><h4>Deal with asynchronous function smartly</h4><p>I would like to explain this concept with Bluebird examples.</p><h3>What makes Bluebird fast?</h3><p>If you open Bluebird library code, you will see bitField parameters. But the bitField is not so important. <br>Bluebird has roughly two states: pending or not. The big difference in handling is between the two states.</p><h4>If the state is pending:</h4><pre><strong>new</strong> Bluebird(<strong>function</strong> executor(resolve) { <br>  // called synchronously<br>  setTimeout(<strong>function</strong> timer() {<br>    resolve(1); <em>// called asynchronously</em><br>  }, 10);<br>})<br>.then(<strong>function</strong> onFulfilled(value) {<br>  <em>//  called asynchronously</em><br>});</pre><p>This execution order is,</p><ol><li>Make a parent instance of Bluebird when new Bluebird is called</li><li>Execute executor</li><li>Execute then.then makes a child instance of Bluebird</li><li>Execute resolve</li><li>Execute onFulfilled</li></ol><p>When then is called, <a href="https://github.com/petkaantonov/bluebird/blob/v3.4.7/src/promise.js#L228">a child instance is created</a>. At that time, resolve is not called yet, so the parent’s state is pending. When the state is pending, <a href="https://github.com/petkaantonov/bluebird/blob/v3.4.7/src/promise.js#L416">the child instance is linked to the parent instance as a child</a>. After that, <a href="https://github.com/petkaantonov/bluebird/blob/v3.4.7/src/promise.js#L513">resolve is called</a> asynchronously by setTimeout. And then, <a href="https://github.com/petkaantonov/bluebird/blob/v3.4.7/src/promise.js#L703-L710">onFulfilled is called with the result</a>.<br>When state is pending, a child instance is linked to parent instance. After resolve is called, onFulfilled is called. It is very simple.</p><h4>If state is not pending:</h4><pre><strong>new</strong> Bluebird(<strong>function</strong> executor(resolve) {<br>  resolve(); <em>// called synchronously</em><br>})<br>.then(<strong>function</strong> onFulfilled(value) {<br>  <em>// ensured asynchronously</em><br>});</pre><p>The execution order is</p><ol><li>Make a parent instance of Bluebird when new Bluebird is called</li><li>Execute executor</li><li>Execute resolve</li><li>Execute then. then makes a child instance of Bluebird</li><li>Execute onFulfilled</li></ol><p>When then is called, the parent’s state is already not pending. In this case, if onFulfilled is called without anything, the function is executed synchronously. For that reason, the library needs to <a href="https://github.com/petkaantonov/bluebird/blob/v3.4.7/src/promise.js#L263-L270">call an asynchronous function</a>. Before calling the function, onFulfilled is <a href="https://github.com/petkaantonov/bluebird/blob/v3.4.7/src/async.js#L88">set to </a>a <a href="https://github.com/petkaantonov/bluebird/blob/v3.4.7/src/async.js#L88">queue</a> and this <a href="https://github.com/petkaantonov/bluebird/blob/v3.4.7/src/async.js#L159">schedule function is called</a>. The schedule is setImmediate on Node.js. And then <a href="https://github.com/petkaantonov/bluebird/blob/v3.4.7/src/async.js#L144">setImmediate calls all queued functions asynchronously</a>.<br>When a state is not pending, onFulfilled is set to a queue, and then queued functions are executed by asynchronous functions.</p><p>You might be wondering why onFulfilled is set to a queue. This is the smartest idea in Bluebird.</p><h4>How to handle the asynchronous function smartly</h4><p>I would like to explain it with this example.</p><pre>Bluebird.resolve(1) <em>// synchronously</em><br>  .then(num <strong>=&gt;</strong> console.log(num)); <em>// asynchronously</em><br>Bluebird.resolve(2) <em>// synchronously</em><br>  .then(num <strong>=&gt;</strong> console.log(num)); <em>// asynchronously</em><br>Bluebird.resolve(3) <em>// synchronously</em><br>  .then(num <strong>=&gt;</strong> console.log(num)); <em>// asynchronously</em></pre><p>If a queue is not used, an asynchronous function is called three times. But if a queue is used, the function executes all queued functions at once.<br>I’m not sure if the bitField gives a big benefit or not. But I think why Bluebird is fast is because of simplicity.</p><h3>What makes Aigle fast?</h3><p>I have just followed these important principles,</p><ul><li>Avoid creating unnecessary variables, functions and instances</li><li>Avoid executing unnecessary functions</li><li>Deal with asynchronous function smartly</li></ul><p>If you follow them, you will be able to make good libraries. I made a <a href="https://github.com/suguru03/aigle/tree/master/benchmark#benchmark">benchmark</a> to check performance between Aigle and Bluebird. The benchmark result is here.</p><ul><li>Node v6.9.1</li><li>Aigle v0.5.0</li><li>Bluebird v3.5.0</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*RTUPNZWTZKBl-WU2zbKM7A.png" /><figcaption>Aigle vs Bluebird</figcaption></figure><p>Aigle has very simple implementation, therefore it is faster than Bluebird. If you are interested in Aigle, I would like you to contribute to it.</p><h4>Intended for production environment</h4><p>The most important part isaigle-core dependency. <br>In Bluebird, every promise instance has to be an instance of Bluebird. When the instance is checked, instanceof function is called. But Bluebird only checks if the instance is made by the <strong>current </strong><strong>Bluebird</strong> class or not. So if many versions are used, Bluebird will be slowed down.<br>The key to avoiding losing performance is to have same dependency. Aigle has aigle-core dependency, therefore every Aigle instance is extended by same AigleCore class. Aigle will keep high performance.</p><p>I would like to show <a href="https://github.com/suguru03/aigle-benchmark">the benchmark example</a>.</p><pre>$ npm list<br>aigle-benchmark@0.0.0 <br>├─┬ aigle@0.5.0 &lt;- aigle@0.5.0 has aigle-core@0.2.0<br>│ └── aigle-core@0.2.0<br>├─┬ benchmark@2.1.3<br>│ └── platform@1.3.3<br>├── bluebird@3.5.0<br>├── lodash@4.17.4<br>├── minimist@1.2.0<br>└─┬ promise-libraries@0.3.0<br>  ├── aigle@0.4.0 &lt;- aigle@0.4.0 has aigle-core@0.2.0 too<br>  └── bluebird@3.4.6</pre><p>As you can see, different aigle dependencies have same aigle-core sub-dependencies. When aigle@0.4.0 is used, the aigle-core is shared.</p><ul><li>Node v6.9.1</li><li>Aigle v0.4.0, v0.5.0</li><li>Bluebird v3.4.6, v3.5.0</li></ul><pre>$ node --expose_gc . -t then<br>======================================<br>[Aigle] v0.5.0<br>[Bluebird] v3.5.0<br>======================================<br>[promise:then:same] Preparing...<br>--------------------------------------<br>[promise:then:same] Executing...<br>[1] &quot;aigle&quot; 180μs[1.00][1.00]<br>[2] &quot;bluebird&quot; 341μs[0.526][1.90]<br>======================================<br>[promise:then:diff] Preparing...<br>--------------------------------------<br>[promise:then:diff] Executing...<br>[1] &quot;aigle&quot; 178μs[1.00][1.00]<br>[2] &quot;bluebird&quot; 506μs[0.352][2.84]</pre><p>promise:then:same was using same versions, and promise:then:diff used child instances of different versions. Aigle never slows down even if the versions are mixed.</p><h3>Conclusion</h3><p>If you follow the three important principles, you will make a fast library. <br>Also Aigle has many functions inspired by <a href="https://github.com/caolan/async">Async</a> and <a href="https://github.com/suguru03/neo-async">Neo-Async</a>. If you still use callback style, I would like to encourage you using Aigle. <br>If I contribute to Node.js and JavaScript communities, I would be happy as a contributor.</p><h3>Reference</h3><ul><li><a href="https://github.com/suguru03/aigle">Aigle</a></li><li><a href="https://github.com/petkaantonov/bluebird">Bluebird</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">MDN</a></li></ul><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f632fd69f3cb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/how-to-make-the-fastest-promise-library-f632fd69f3cb">How to make the fastest Promise library</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>