#Intervals
1 messages · Page 1 of 1 (latest)
runInterval is viable, but its effectiveness depends on how much work you're doing per interval and how frequently you're executing it, since it's tick-based, running it too often or doing too much can impact performance. In some instances, using runJob may be suitable for micro execution if it's something you don't intend to run in intervals but need to execute quickly and not block the thread by offering better support for yielding.
You could try using PulseScheduler from bedrock boost - https://github.com/Bedrock-OSS/bedrock-boost
import { PulseScheduler } from "@bedrock-oss/bedrock-boost"
// Define a processor function to apply an effect to an entity
const applyEffect = (entity) => {
// Example function applying an effect to the entity
console.log(`Applying effect to entity: ${entity}`);
};
// Create a PulseScheduler with a 100-tick interval
const entityEffectScheduler = new PulseScheduler(applyEffect, 100);
// Add entities to the scheduler
entityEffectScheduler.add("Entity1");
entityEffectScheduler.add("Entity2");
// Start the scheduler to begin processing entities
entityEffectScheduler.start();```
.
This separates out individual calls evenly over ticks. So it depends on what you're using the run interval for