Git Product home page Git Product logo

vcmloop's Introduction

npm package

version build language download dependents issue last_commit license

An interval-based looping method for massive data

Doing simple looping basicly doesn't have big impact to your RAM/CPU resource, but, it will if you performing heavy looping with massive data, for example 100k data or > 1m data.

Default looping method like for, while, foreach runs faster (has better performance), but also takes and spent more RAM/CPU resource continously along with the looping process—if you own more resource, I think it's not a big problem. Otherwise, using interval method doesn't harm RAM/CPU resource too much. It just uses a little bit of it and keeping the resource stable until the process is done. As a consequence, it runs slower than the default method—but still fast.

So, if you need to do looping with massive data and heavy process inside, using interval method should be a better solution.

Installation

NPM

npm install vcmloop --save

Browser

// Bower
bower install vcmloop --save

Initialization

NPM

const vcmloop = require('vcmloop');

Browser

// Bower
<script src="bower_components/vcmloop/dist/vcmloop.min.js"></script>

Quickstart

vcmloop(start, stop, fn, end[optional], delay[optional]);
  • Arguments
    • number start
    • number stop
    • function fn
    • function end [optional]
    • number delay [optional]
      • default 0

Here is basic vcmloop usage:

vcmloop(0, 5, (num) => {
  console.log(num);
});

You can pass an end argument to run once after the synchronous looping process is done.

vcmloop(0, 5, (num) => {
  console.log(num);
}, () => {
  console.log('end');
});

// output:
// 0
// 1
// 2
// 3
// 4
// end

You can set duration or delay for interval process.

vcmloop(0, 5, (num) => {
  console.log(num);
}, null, 200);
vcmloop(0, 5, (num) => {
  console.log(num);
}, () => {
  console.log('end');
}, 200);

You may do this in an asynchronous looping process to make sure your code runs correctly:

var len = 10;
var lenX = len - 1;
var start = 0;

vcmloop(start, len, (num) => {
  console.log(num);
  
  sampleFunction(sampleCallback => {
    if (num === lenX) return 'end';
  });
});

Release

Changelog

See https://github.com/dalikewara/vcmloop/blob/master/CHANGELOG.md.

Credits

Copyright © 2019 Dali Kewara.

License

MIT License

vcmloop's People

Contributors

dalikewara avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.