Coder Social home page Coder Social logo

seq_queue's Introduction

seq_queue

Seq_queue is simple tool to keep requests to be executed in order.

As we known, Node.js codes run in asynchronous mode and the callbacks are unordered. But sometimes we may need the requests to be processed in order. For example, in a game, a player would do some operations such as turn right and go ahead. And in the server side, we would like to process these requests one by one, not do them all at the same time.

Seq_queue takes the responsibility to make the asynchronous, unordered processing flow into serial and ordered. It's simple but not a repeated wheel.

Seq-queue is a FIFO task queue and we can push tasks as we wish, anytime(before the queue closed), anywhere(if we hold the queue instance). A task is known as a function and we can do anything in the function and just need to call task.done() to tell the queue current task has finished. It promises that a task in queue would not be executed util all tasks before it finished.

Seq_queue add timeout for each task execution. If a task throws an uncaught exception in its call back or a developer forgets to call task.done() callback, queue would be blocked and would not execute the left tasks. To avoid these situations, seq-queue set a timeout for each task. If a task timeout, queue would drop the task and notify develop by a 'timeout' event and then invoke the next task. Any task.done() invoked in a timeout task would be ignored.

fock by https://github.com/changchang/seq-queue

usage

import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
import { createQueue, STATUS_IDLE } from "https://deno.land/x/seq_queue/mod.ts";

Deno.test("seq_queue", function() {
  const timeout = 1000;
  const queue = createQueue(timeout);
  assertEquals(queue.status, STATUS_IDLE);
  // deno-lint-ignore no-explicit-any
  queue.push(function(task: any) {
    task.done();
    assertEquals(queue.status, STATUS_IDLE);
  });
});

seq_queue's People

Contributors

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