Skip to content

Instantly share code, notes, and snippets.

@FreeMasen
Last active January 26, 2022 20:32
Show Gist options
  • Save FreeMasen/388c7b413c0150d6f41f4af30d831070 to your computer and use it in GitHub Desktop.
Save FreeMasen/388c7b413c0150d6f41f4af30d831070 to your computer and use it in GitHub Desktop.
local cosock = require "cosock"
local tx1, rx1 = cosock.channel.new()
local tx2, rx2 = cosock.channel.new()
cosock.spawn(function()
print('1 started')
assert(rx2:receive())
print('1 exiting')
tx1:send(1)
end)
cosock.spawn(function()
print('2 started')
tx2:send(1)
assert(rx1:receive())
print('2 exiting')
end)
-- This prints
-- 1 started
-- 2 started
-- 1 exiting
-- 2 exiting
cosock.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment