dsw
@rbxts/delay-spawn-wait
npm i @rbxts/delay-spawn-wait
dsw

@rbxts/delay-spawn-wait

Various libraries I have posted on npm

by Niles Salter

2.0.0 (see all)License:ISCTypeScript:Not Found
npm i @rbxts/delay-spawn-wait
Readme

delay-spawn-wait

This library works as a (mostly) drop-in replacement for the built-in functions by the same names. The main differences are:

  • This library neither exposes the result of an elapsedTime() call as a second return value of wait() nor as a second argument passed into the callback given to delay.

    -- below, we compare vanilla behavior against this library's behavior:
    
    print(wait())
    -- vanilla: 0.15499839999939 13074.348632812
    -- library: 0.15499839999939
    
    -- if you want to get that second number, instead call elapsedTime()
    
    print(wait(), elapsedTime())
    -- vanilla: 0.15499839999939 13074.348632812
    -- library: 0.15499839999939 13074.348632812
    
    delay(0, print)
    -- vanilla: 0.15499839999939 13074.348632812
    -- library: 0.15499839999939
    
  • spawn runs on a new thread without yielding one tick (or passing in a deltaTime parameter)

    • If you need to yield for one tick, try delay(0, callback) instead.
      • Keep in mind that one tick in this library is on the Heartbeat (60hz) pipeline, and NOT on the 30hz pipeline. That means 1 tick approximately equals 1/60 of a second instead of 1/30 of a second (when running at 60fps).
  • spawn and delay allow you to pass in extra arguments with which to call the callback.

    spawn(print, 0, 1, 2) -- 0 1 2
    
    -- note: delay still passes deltaTime in as the first argument to the callback!
    delay(0, print, 0, 1, 2) -- 0.0030354000009538 0 1 2
    
  • delay can accept a BindableEvent to fire instead of a callback:

    local bindable = Instance.new("BindableEvent")
    delay(5, bindable)
    bindable.Event:Wait() -- this is what our wait() function does internally!
    
    • Note that passing in extra arguments with a BindableEvent will pass your arguments directly into BindableEvent:Fire(). That means these rules apply.
      local b = Instance.new("BindableEvent")
      delay(2, b, 1, newproxy(true))
      b.Event:Connect(function(elapsedTime, num, userdata)
          -- elapsedTime: (number)
          -- num: 1
          -- userdata: nil
      end)
      

Downloads/wk

3

GitHub Stars

18

LAST COMMIT

8mos ago

MAINTAINERS

1

CONTRIBUTORS

7

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
2.0.0
latest
2yrs ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate