Skip to content

Commit

Permalink
Create async.lua.md
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Jun 28, 2023
1 parent 91a4e75 commit f8e7916
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ludobits/m/async.lua.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Co-routine wrapper for asynchronous operations

Usage:

```lua
local async = require("ludobits.m.async")

local co = coroutine.create(function()
-- do an http request and wait for the response
local response = async.http_request("https://www.foobar.com", "GET", headers)
print(response.code)

-- animate a game object over time and wait until completed
local to = vmath.vector3(100, 100, 0)
local duration = 5 -- seconds
local delay = 1 -- second
async.go_animate(".", "position", go.PLAYBACK_ONCE_FORWARD, to, go.EASING_LINEAR, duration, delay)

-- wait 5 seconds
async.delay(5)

print("We're done!)
end)
coroutine.resume(co)
```

0 comments on commit f8e7916

Please sign in to comment.