Jump to content



Recommended Posts


BAsync - module to write concurrent code using the async/await syntax for Gothic 2 Online.

Project links:
- Repository

Usage example

// Closure to async function
basync.run(function (ctx) {
    basync.await(ctx, basync.sleep(2500))

// Closure to async function with parameters
basync.run(function (ctx, a, b) {
    print("A: " + a)
    basync.await(ctx, basync.sleep(2500))
    print("B: " + b)
}, [1, 2])

// Deep nested async functions
local function f3(ctx) {
    print("THREAD: 3")
    basync.await(ctx, basync.sleep(1000))
    print("THREAD: 3")

local f2 = basync(function (ctx, a, b) {
    print("THREAD: 2")

    // Only function marked as async can be awaited!
    basync.await(ctx, basync(f3)())

    print("THREAD: 2")
    printf("RESULT: %d", a + b)

local f1 = basync(function (ctx) {
    print("THREAD: 1")
    basync.await(ctx, basync.sleep(1000))
    print("THREAD: 1")
    basync.await(ctx, f2(1, 2))
    print("THREAD: 1")

local r = basync.run(f1())


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...