Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing on Async function to EndPoint(Ajax) #225

Open
evicent opened this issue Feb 23, 2018 · 1 comment
Open

Implementing on Async function to EndPoint(Ajax) #225

evicent opened this issue Feb 23, 2018 · 1 comment

Comments

@evicent
Copy link

evicent commented Feb 23, 2018

Hi!. Im trying to implement a later.setInterval function, and the function is an async call to API (Ajax). Is there any reestriccion? The thing is that the function is executed just once. I change the api function using a 'console.log' function, and worked properly...any comments?

Regards!!

@happydenn
Copy link

@evicent It seems like later can work with an async function just fine. The following is a simple example grabbing a random Star Wars character every 5 seconds using later.setInterval

const later = require('later')
const axios = require('axios')

const s = later.parse.text('every 5 seconds')

later.setInterval(async () => {
  const randomIndex = Math.ceil(Math.random() * 20)
  const { data } = await axios.get(`https://swapi.co/api/people/${randomIndex}/`)

  console.log(data)
}, s)

Maybe you can provide a simple example on what isn't working properly for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants