npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@insulo/runner

v0.1.6

Published

Execute functions and promises with logging runtime information like duration; run them in sequential or parallel order or with piping the return as param through an array of those.

Downloads

7

Readme

Insulo: Runner

Execute functions and promises with logging runtime information like duration; run them in sequential or parallel order or with piping the return as param through an array of those.

Having the two entrypoints @insulo/runner and @insulo/runner/pretty to choose from, where pretty just wraps the base implementation with closures, some implementations are needing everything wrapped and some not.

  • @insulo/runner @insulo/runner/pretty
  • run run execute with runtime configuration, pass params for fn, add a name, disable logging
  • runSequential sequential execute an array, wait e.g. for the first promise to have finished before starting second
  • runParallel parallel execute an array in parallel (not multi-threaded)
  • runPipe pipe execute an array sequential and pass down the return values as params
  • log utility console.log wrapper with coloring, timestamp etc.
    • log.raw ()<string: text, Date|undefined: time>
    • log.error
    • log.start
    • log.end

Example Usage with pretty/dsl-like functions

How run, sequential, parallel, pipe and log can be used to execute a lot of things.

someThing can be: function, function wrapping a promise or just a promise

const {run, sequential, parallel, pipe, log} = require('@insulo/runner/pretty');

run(
    sequential([
         someThing0,
         parallel([
             pipe([
                 someThing1,
                 someThing2,
             ]),
             someThing3
         ]),
         sequential([
             someThing4,
             someThing5
         ]),
         run(
             someThing6,
             ['param'],
             'task-name'
         ),
         someThing7,
    ]),
    ['param1', 2],
    'task-root-name'
    
// this run must be executed 
)().then(res => {
    // this log is an object
    log.raw('log e.g. the result');
    log.raw(JSON.stringify(res));
}).catch(e =>{});

Example Usage with base implementation Runner

How Runner.run, Runner.runSequential, Runner.runParallel, Runner.runPipe and Runner.log can be used to execute a lot of things.

someThing can be: function, function wrapping a promise or just a promise

const Runner = require('@insulo/runner');

Runner.run(
    () => Runner.runSequential([
         someThing0,
         () => Runner.runParallel([
             () => Runner.runPipe([
                 someThing1,
                 someThing2,
             ]),
             someThing3
         ]),
         () => Runner.runSequential([
             someThing4,
             someThing5
         ]),
         () => Runner.run(
             someThing6,
             ['param'],
             'task-name'
         ),
         someThing7,
    ]),
    ['param1', 2],
    'task-root-name'
    
// this run is executed automatically
).then(res => {
    // this log is a function returning an object
    Runner.log().raw('log e.g. the result');
    Runner.log().raw(JSON.stringify(res));
}).catch(e =>{});

Example Mixed Usage

someThing can be: function, function wrapping a promise or just a promise

const Runner = require('@insulo/runner');
const {run, sequential, parallel, pipe, log} = require('@insulo/runner/pretty');

Runner.run(
    sequential([
         someThing0,
         parallel([
             pipe([
                 someThing1,
                 someThing2,
             ]),
             someThing3
         ]),
         sequential([
             someThing4,
             someThing5
         ]),
         run(
             someThing6,
             ['param'],
             'task-name'
         ),
         someThing7,
    ]),
    ['param1', 2],
    'task-root-name'
    
// this run is executed automatically
).then(res => {
    log.raw('log e.g. the result');
    log.raw(JSON.stringify(res));
}).catch(e =>{});

Example log

Using the logger from Runner:

const Runner = require('@insulo/runner');

//
// Raw

Runner.log().raw('Text');
Runner.log().raw('Text', new Date());
// [10:45:50] Text

//
// Error

Runner.log().error('Text');
Runner.log().error('Text', new Date());
// [10:45:50] #! Text

//
// Start and End

let start_date = Runner.log().start('Name');
let start_date = Runner.log().start('Name', new Date());
// [10:45:50] Starting `Name`

Runner.log().end('Name', start_date);
Runner.log().end('Name', start_date, new Date());
// [10:45:50] Finished `Name` after 50ms
Runner.log().end('Name', start_date, undefined, 'Suffix');
Runner.log().end('Name', start_date, new Date(), 'Suffix');
// [10:45:50] Finished `Name` after 50ms Suffix

Using log from pretty:

const {log} = require('@insulo/runner/pretty');

//
// Raw

log.raw('Text');
log.raw('Text', new Date());
// [10:45:50] Text

//
// Error

log.error('Text');
log.error('Text', new Date());
// [10:45:50] #! Text

//
// Start and End

let start_date = log.start('Name');
let start_date = log.start('Name', new Date());
// [10:45:50] Starting `Name`

log.end('Name', start_date);
log.end('Name', start_date, new Date());
// [10:45:50] Finished `Name` after 50ms
log.end('Name', start_date, undefined, 'Suffix');
log.end('Name', start_date, new Date(), 'Suffix');
// [10:45:50] Finished `Name` after 50ms Suffix

Licence

This project is free software distributed under the terms of two licences, the CeCILL-C and the GNU Lesser General Public License. You can use, modify and/ or redistribute the software under the terms of CeCILL-C (v1) for Europe or GNU LGPL (v3) for the rest of the world.

This file and the LICENCE.* files need to be distributed and not changed when distributing. For more informations on the licences which are applied read: LICENCE.md

Copyright

2018 | bemit UG (haftungsbeschränkt) - [email protected]
Author: Michael Becker - [email protected]