Bimbol Posted June 8, 2023 Share Posted June 8, 2023 Introduction 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) { print("A") basync.await(ctx, basync.sleep(2500)) print("B") }) // 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") print("FINISHED") }) local r = basync.run(f1()) print(r.task.getstatus()) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.