API Docs for: 0.0.1
Show:

Utils Class

Module: utils

Collection of various utility functions.

Copyright (c) 2014 ITSA - https://github.com/itsa New BSD License - http://choosealicense.com/licenses/bsd-3-clause/

Item Index

Methods

_asynchronizer

(
  • callbackFn
)
private static

Forces a function to be run asynchronously, but as fast as possible. In Node.js this is achieved using setImmediate or process.nextTick.

Parameters:

  • callbackFn Function

    The function to call asynchronously

async

(
  • callbackFn
  • [invokeAfterFn=true]
)
Object

Invokes the callbackFn once in the next turn of the JavaScript event loop. If the function requires a specific execution context or arguments, wrap it with Function.bind.

I.async returns an object with a cancel method. If the cancel method is called before the callback function, the callback function won't be called.

Parameters:

  • callbackFn Function
  • [invokeAfterFn=true] Boolean optional

    set to false to prevent the _afterSyncFn to be invoked

Returns:

Object:

An object with a cancel method. If the cancel method is called before the callback function, the callback function won't be called.

async

(
  • callbackFn
  • [invokeAfterFn=true]
)
Object

Invokes the callbackFn once in the next turn of the JavaScript event loop. If the function requires a specific execution context or arguments, wrap it with Function.bind.

I.async returns an object with a cancel method. If the cancel method is called before the callback function, the callback function won't be called.

Parameters:

  • callbackFn Function
  • [invokeAfterFn=true] Boolean optional

    set to false to prevent the _afterSyncFn to be invoked

Returns:

Object:

An object with a cancel method. If the cancel method is called before the callback function, the callback function won't be called.

idGenerator

(
  • [namespace]
  • [start]
)
Number | String

Generates an unique id with the signature: "namespace-follownr"

Parameters:

  • [namespace] String optional

    namespace to prepend the generated id. When ignored, the generator just returns a number.

  • [start] Number optional

    startvalue for the next generated id. Any further generated id's will preceed this id. If start is lower or equal than the last generated id, it will be ignored.

Returns:

Number | String:

an unique id. Either a number, or a String (digit prepended with "namespace-")

Example:

var generator = require('core-utils-idgenerator');

console.log(generator()); // --> 1
console.log(generator()); // --> 2
console.log(generator(1000)); // --> 1000
console.log(generator()); // --> 1001
console.log(generator('Parcel, 500')); // -->"Parcel-500"
console.log(generator('Parcel')); // -->"Parcel-501"

later

(
  • callbackFn
  • [timeout]
  • [periodic]
)
Object

Invokes the callbackFn after a timeout (asynchronous). If the function requires a specific execution context or arguments, wrap it with Function.bind.

To invoke the callback function periodic, set 'periodic' either 'true', or specify a second timeout. If number, then periodic is considered 'true' but with a perdiod defined by 'periodic', which means: the first timer executes after 'timeout' and next timers after 'period'.

I.later returns an object with a cancel method. If the cancel() method is called before the callback function, the callback function won't be called.

Parameters:

  • callbackFn Function

    the function to execute.

  • [timeout] Number optional

    the number of milliseconds to wait until the callbackFn is executed. when not set, the callback function is invoked once in the next turn of the JavaScript event loop.

  • [periodic] Boolean | Number optional

    if true, executes continuously at supplied, if number, then periodic is considered 'true' but with a perdiod defined by 'periodic', which means: the first timer executes after 'timeout' and next timers after 'period'. The interval executes until canceled.

Returns:

Object:

a timer object. Call the cancel() method on this object to stop the timer.