LibFiber

LibFiber

1k Downloads

This library will help you to split big amount of calls that you can't control under combat lockdown to separate "fibers" in same frame to avoid "script ran too long" errors.

Available functions

Just one for the moment:

lib:WrapVoidMethod(object, method)

Given object and method name, this function will replace original method with a wrapper that will either just call the original if you're out of combat or reschedule it to separate "fiber" in same frame created through Blizzard's timer call that happen to have separate execution time limit and thus helps to avoid "script ran too long" error caused by sheer amount of calls per frame.

This function is intended to wrap calls that are fast enough by themselves but that could be called in amounts that you, as developer, can't control. For example: action or macro buttons if your addon allows to create unlimited amount - even if one button update reliably takes, say, 2ms, user who creates over 100 buttons will hit "script ran too long"; item slot buttons - their amount just naturally increases as Blizzard introduces larger bags; etc.

Wrapped method must have no arguments or returns except implied "self" as they're silently dropped. This generally fits the signature of :Update methods that read data from their instance.

DO try to optimize problematic function as much as possible - even if you wrap it, total time of calls will still incur noticeable FPS hiccup and wrapper will also add some overhead to that. DO separate multiple calls manually to different frames if your updates have some predictable pattern and don't really need visual or whatever result instantly. For example updating texture, count or cooldown on item slot should happen as soon as player opens bag window or relevant event happens, while drawing highlight border for custom search can be split over several next frames and player won't even notice it.

Included EXAMPLE.lua file shows example of usage and allows you to test how it works.