Giter Club home page Giter Club logo

heldrida / call-moe-dee Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 7 KB

Yo! Ain't me who's gonna leave calls in the Wild Wild West! Call Moe Dee (inspired by Kool Moe Dee, Wild Wild West theme song) is a helper function that make timed recursive calls, if a given condition does not pass. When the condition test passes, a callback function is called, terminating the timed recursive calls! Also, for each recursive or step in the call stack, there is a stepCallback callback function if required. So, hell yeah! No mo' breakin' neck guessing when you is able to make those goddam calls!

JavaScript 100.00%

call-moe-dee's Introduction

Call Moe Dee

Yo! Ain't me who's gonna leave those calls in the WWW! Call-Moe-Dee (inspired by Kool Moe Dee, Wild Wild West song) is a helper function that makes timed recursive calls, if a given condition does not pass, repeatedly, over a period of time, until a condition is met! When the condition test passes, a callback function is called, terminating the timed recursive calls! Also, for each recursive or step in the call stack, there is a stepCallback callback function, if required. So, hell yeah! No mo' breakin' da neck guessing when you is able to make those goddam calls doug!

IMAGE ALT TEXT

How to use

npm install call-moe-dee

Import it into your project like you do with your regular libraries

import callMoeDee from 'call-mode-dee'

or, that funky ol' school way brotha and sista

var callMoeDee = require('call-moe-dee')

Pass the parameters to callMoeDee, that will resolve to the callback once your condition pass!

const params = {
  name: 'My callMoeDee test',
  time: {
    maxMs: 10000, // if omitted, defaults to 40000ms
    retryAfterMs: 200, // if omitted, defaults to 1000ms
    exceedMaxTimeCallback: () => {
      console.log('The caller exceedMaxTimeout!')
    }
  },
  stepCallback: () => {
    // this parameter is optional (triggered in each step)
  },
  condition: {
    test: () => (global && global.stop),
    callback: () => {
      console.log('Hello world!')
    }
  },
  debug: true
}

callMoeDee(params)

Example

import callMoeDee from 'call-mode-dee'

// We'll modify this at a later stage
let global = {
  stop: false
}

// Initialize it
callMoeDee({
  name: 'My callMoeDee test', // for your convenience, to help debug, etc
  time: {
    exceedMaxTimeCallback: () => {
      console.log('The caller exceedMaxTimeout!')
    }
  },
  stepCallback: () => {
    console.log('Step call!')
  },
  condition: {
    test: () => (global && global.stop),
    callback: () => {
      console.log('Hello world!')
    }
  },
  debug: true
})

// After some time we modify the global.stop property
setTimeout(() => {
  global.stop = true
  console.log('global.stop: ', global.stop)
}, 5000)

call-moe-dee's People

Contributors

heldrida avatar

Watchers

 avatar  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.