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

browser-scheduler

v1.0.1

Published

scheduler for absolutly control

Downloads

2

Readme

Scheduler

Why?

Usage

Api

Example (can run inside latest chrome)

Why?

Sometimes for smooth work (60fps) for us applications (SPA) we should manage queue and priority functions.

For this goal was created this Scheduler.

Usage

Flow is used for additional information

import Scheduler from 'Scheduler'

type Task = {
  handler: Function,
  priority?: number // some props for choose task priorty
}

getTaskWrapperFunction - This function allows us to control the execution queue tasks.

For example, a tasks can be executed synchronously, as a microtask or a macrotask.

It helps for improve performane application.

For understand

function getTaskWrapperFunction (task: Task): Function {
  const { priority } = task

  switch (true) {
    case priority === 1: {
      return // sync perform of task.handler
    }
    case priority === 2: {
      return nextTick // what is it? - http://blog.millermedeiros.com/promise-nexttick/
    }
    case priority === 3: {
      return setImmediate // pollyfill - https://github.com/YuzuJS/setImmediate
    }
    default: {
      return setTimeout
    }
  }
}

getFrameFunction - This function determines the execution time of tasks for each iteration

function getFrameFunction (tasksForFrame: Array<Task>): Function {
  var countTasks = tasksForFrame.length

  switch (true) {
    case countTasks < 30: {
      return raf
    }
    case countTasks < 100: {
      return doubleRaf
    }
    default: {
      return longRaf
    }
  }
}
// Primitive example of functions
var raf = window.requestAnimationFrame
function doubleRaf (cb) { return raf(() => raf(cb)) }
function longRaf (cb) { return setTimeout(cb, 16 * 4) }

beforeFrame - This function is performed at the beginning of each iteration

function beforeFrame (): void { (this: typeof Scheduler) }

afterFrame - This function is executed at the end of each iteration

function afterFrame (): void { (this: typeof Scheduler) }

Init and start

const instance = new Scheduler({
  getTaskWrapperFunction,
  getFrameFunction,
  beforeFrame,
  afterFrame
})

instance.start()

API

new Scheduler({ getTaskWrapperFunction?, getFrameFunction?, beforeFrame?, afterFrame? }) - Init Scheduler

getTaskWrapperFunction(task: Task): Function -

getFrameFunction(tasks: Array<Task>): Function -

beforeFrame(): void { (this: typeof Scheduler) } -

afterFrame(): void { (this: typeof Scheduler) } - description inside Usage

start() - Launch scheduler

stop() - Stops scheduler

addTask(task: Task) - Add once task

subscribeTask(task: Task) - Add task for every iteration

unsubscribeTask(task.handler: Function) - Remove task from subscribes tasks

clearTasks() - Remove all tasks from queue

clearFrameTasks() - Remove all tasks from iteration (ex. can call it inside beforeFrame)

clearSubscribesTasks() -- Remove all subscribes tasks