callforth

WebJar for callforth

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

callforth
Последняя версия

Последняя версия

0.3.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

callforth
WebJar for callforth
Ссылка на сайт

Ссылка на сайт

https://www.webjars.org
Система контроля версий

Система контроля версий

https://github.com/gruhn/callforth

Скачать callforth

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/callforth/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>callforth</artifactId>
    <version>0.3.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/callforth/
implementation 'org.webjars.npm:callforth:0.3.1'
// https://jarcasting.com/artifacts/org.webjars.npm/callforth/
implementation ("org.webjars.npm:callforth:0.3.1")
'org.webjars.npm:callforth:jar:0.3.1'
<dependency org="org.webjars.npm" name="callforth" rev="0.3.1">
  <artifact name="callforth" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='callforth', version='0.3.1')
)
libraryDependencies += "org.webjars.npm" % "callforth" % "0.3.1"
[org.webjars.npm/callforth "0.3.1"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

Callforth 🏃

npm version minzipped size

A tiny utility library to replace callbacks with Promises where possible. Don't callback, callforth!

It simply includes a hand-full of functions I see myself re-implementing in nearly every project. So I might as well put them in a package.

Do things like:

await timeout(3000)
await eventOn(videoElement, "loadeddata")
const message = await eventOn(webWorker, "message")

Install 📦

npm install callforth

Now you can:

import { eventOn, timeout, polling } from "callforth"

Alternatively, include this script and:

<script src="./path/to/callforth.umd.js"></script>
<script>
  const { eventOn, timeout, polling } = window.callforth
</script>

API 👀

eventOn

const payload = await eventOn(target, successEvent, errorEvent)

Parameters

  • target : EventTarget - any object you can call addEventListener on.
  • successEvent : string - name of the event you want to await.
  • errorEvent : string (optional) - if this event fires, the promise is rejected.

Return Value

  • Promise<any> - wraps callback result (callbacks first argument)

timeout

await timeout(delay)

Parameters

  • delay : int - milliseconds after which the Promise should resolves.

Return Value

  • Promise<void>

polling

await polling(predicate, { maxTries, interval })

Parameters

  • predicate : any -> boolean - delay in milliseconds after which the Promise should resolve.
  • options : object (optional)
    • maxTries : int (default = 10) - maximum number of times to call predicate before giving up.
    • interval : int (default = 10) - delay in milliseconds between calls of predicate.

Return Value

  • Promise<void>

More Examples

async function loadScript(url) {
  let script = document.createElement("script")

  script.src = url

  await eventOn(script, "loaded")
}
async function primesLessThen(number) {
  primeWorker.postMessage(number)

  const result = await eventOn(primeWorker, "message")

  return result
}

Версии библиотеки

Версия
0.3.1