Socket
Socket
Sign inDemoInstall

@jill64/async-observer

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jill64/async-observer

🔭 Make Promise state observable as a string


Version published
Maintainers
1
Created
Source

async-observer

npm-version npm-license npm-download-month npm-min-size ci.yml codecov-coverage

🔭 Make Promise state observable as a string

Installation

npm i @jill64/async-observer

Example

import { observable } from '@jill64/async-observer'

const { status, observed } = observable({
  // FULFILLED => IDLE at 100ms
  resolveToIdle: 100,
  // REJECTED => IDLE at 500ms
  rejectToIdle: 500
})

const run = observed(async () => {
  // e.g. Duration as 1000ms
  await yourAsyncFunction()
})

let str = ''

status.subscribe((status) => {
  str = status
})

// str => IDLE

run()

// str => PENDING

// ↓ After the 1000ms

// str => FULFILLED

// ↓ After the 100ms

// str => IDLE

Compatibility for svelte store

Since status is implemented according to svelte store, it can be used in svelte applications as follows

<script>
  import { observable } from '@jill64/async-observer'

  const { status, observed } = observable()

  $: set = observed(async () => {
    await yourAsyncFunction()
  })
</script>

<button on:click={set}>Button</button>

<div>{$status}</div>

Keywords

FAQs

Package last updated on 19 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc