Coder Social home page Coder Social logo

caller's Introduction

☎️ Caller


👩‍🔬 Please be aware that this package is still experimental, changes to the interface and underlying implementation are likely, and future development or maintenance is not guaranteed.


This package provides different interchangeable function (Callable) call strategies to manage call execution. The different strategies can be used to switch from synchronous to asynchronous executions and back for optimal performance.

Homer Simpson yelling "WHOO-HOO!" on the phone

Example

import {
  AsynchronousCaller,
  ImmediateCaller,
  SynchronousCaller
} from "@orlandohohmeier/caller";

function print(msg)
  console.log(msg);
}

Promise.all([
  new AsynchronousCaller().call(null, print, "c"),
  new ImmediateCaller().call(null, print, "b"),
  new SynchronousCaller().call(null, print, "a")
]).then(() => print("done"));

/codesandbox: https://codesandbox.io/s/ryy86omk94?module=%2Fsrc%2Findex.js

Asynchronous Caller

This caller uses setTimeout (Tasks) to defer calls until the stack is empty. The asynchronous strategy is useful when the calls take potentially longer as it allows the browser to render updates in between.

Immediate Caller

The immediate caller uses Promise.resolve() (MicroTasks) to postpone calls until the current task is done but before the next task is running. The caller makes the respective calls async without the penalty of a new task.

Please note that as the calls are scheduled to run before the next task, the browser may not be able to render update between calls.

Synchronous Caller

This caller synchronously calls the provided Callable (e.g. function).

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.