question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How does `fetch` work?

See original GitHub issue

When I implement fetch in an event the event only fires once. the only way to get it to fire again is to reload.

import {event, command, reload, fetch} from '@grakkit/stdlib-paper'

event('org.bukkit.event.entity.PlayerDeathEvent', event => {
    fetch('https://raw.githubusercontent.com/LearnWebCode/json-example/master/animals-1.json').json(true)
    .then(data => console.log(JSON.stringify(data)))
})

command({
    name: 'jsReload',
    execute: () => reload(),
})

Is there something I’m doing wrong?

Edit: I’ve found a workaround, but if there’s a better way, that would be appreciated. Instead of implementing the fetch in the event, have the event dispatch a command that makes the request, how you’d get the resulting data back to the event, I haven’t tried to figure out as I don’t need it to, but I figure that’s pretty niche

import {event, command, server, reload, fetch} from '@grakkit/stdlib-paper'

event('org.bukkit.event.entity.PlayerDeathEvent', event => {
     server.dispatchCommand(server.getConsoleSender(), `getExternalCommand`)
})

command({
    name: 'jsReload',
    execute: () => reload(),
})
command({
    name: 'getExternalResource',
    execute: (sender, args) => {
        let res = fetch('https://raw.githubusercontent.com/LearnWebCode/json-example/master/animals-1.json').json()
        console.log(res)
    },
    
})

Notice the fetch is no longer async, that’s because for some reason when it is, it generates an exception while executing task 261148 java.lang.IllegalStateException: Multi threaded access requested by thread Thread[Craft Scheduler Thread - 1309 - grakkit,5,main] but is not allowed for language(s) js.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
GodBleakcommented, Jul 30, 2022

@Mythical-Forest-Collective I’m not sure, I decided to shift my approach altogether. I’d like to check, however, I’m currently racing to finish another project before I leave on vacation for a few weeks. If time is of the essence, Let me know and I will check within the next few days, otherwise, I’d love to check when I get back, and if needed I can close this until then.

0reactions
spacefluff432commented, Jul 30, 2022

stdlib v1 is being replaced soon, the fetch method is just an HTTP get system with async. it’s very basic and under-featured.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How Does The Fetch Rewards App Work?
How does Fetch Rewards work? Fetch pays you — that's right, pays you — in digital gift cards for scanning your receipts, which...
Read more >
How does Fetch work?
Fetch gives you points for shopping and submitting your receipts with the app. You can then use those points to redeem gift cards...
Read more >
Fetch Rewards: 5 Things You Need To Know To Get Free Gift ...
Fetch Rewards is a free shopping app that awards points in exchange for scans of your receipts. You can then redeem those points...
Read more >
Fetch Rewards Review: 10 Things to Know Before You Sign Up
With Fetch Rewards, all you have to do is upload your receipt to the app and you'll receive points immediately. There are no...
Read more >
How Does Fetch Rewards Make Money? Dissecting Its ...
Fetch Rewards is a shopping platform that enables users to earn rewards in exchange for scans of their receipt. Using the platform is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found