0.0.10 • Published 5 years ago

genyaj v0.0.10

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Work in progress

Genyaj

Helps perform asynchronous tasks on regular interval using javascript generators and recursion.

Installation

npm i genyaj
import { Generate } from 'genyaj'

Generate({
    /*
    @required
    @function
    Runs every _interval_
    */
    task: () => console.log('updated'),
    /*
    @optional
    @function
    Stop generator when evaluates to true
    */
    stop: () => stop,
    /*
    @optional
    @number
    @default 0
    Time (ms) between each _task_ execution
    If none, _task_s will run consecutively
    */
    interval: 1000
})

Example with React Hooks

import React, { useState, useEffect } from 'react'
import axios from 'axios'
import { Generate } from 'genyaj'

const ItemDisplay = () => {
    const [items, setItems] = useState([])

    const getItemUpdates = async () => {
        const { data } = await axios.get(API)
        setItems(data)
    }

    useEffect(() => {
        Generate({
            task: getItemUpdates,
            interval: 5000
        })
    }, [])

    return (
        <div>
            {items.map(item => <p>{item.name}</p>)}
        </div>
    )
}
0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago