Skip to main content
Module

x/froebel/mod.ts>createQueue

A strictly typed utility library.
Go to Latest
variable createQueue
import { createQueue } from "https://deno.land/x/froebel@v0.23.0/mod.ts";

Creates a queue function that accepts a function as it's only parameter. When queue is invoked, the passed in function is executed after the last function passed to queue has finished executing. The queue function returns the result of the passed in function asynchronously.

Reading queue.done is true if no functions are currently executing / scheduled and otherwise a promise that resolves once the last function has stopped executing and no futher functions are queued.

Examples

Example 1

const queue = createQueue()

queue(async () => {
  console.log('start a')
  await delay()
  return 'end a'
}).then(console.log)

queue(async () => {
  console.log('start b')
  await delay()
  return 'end b'
}).then(console.log)

queue(async () => {
  console.log('start c')
  await delay()
  return 'end c'
}).then(console.log)

await queue.done

// start a
// end a
// start b
// end b
// start c
// end c

type

() => Queue