Skip to content

Commit

Permalink
Merge pull request #925 from permaweb/twilson63/fix-bug-w-ao-receive
Browse files Browse the repository at this point in the history
fix: bug with ao receive
  • Loading branch information
twilson63 authored Jul 29, 2024
2 parents 8254155 + 4e6de6d commit ac2ca70
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 308 deletions.
8 changes: 5 additions & 3 deletions dev-cli/container/src/ao.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ end
function ao.send(msg)
assert(type(msg) == 'table', 'msg should be a table')
ao.reference = ao.reference + 1
local referenceString = tostring(ao.reference)

local message = {
Target = msg.Target,
Expand All @@ -129,7 +130,7 @@ function ao.send(msg)
{name = "Data-Protocol", value = "ao"},
{name = "Variant", value = "ao.TN.1"},
{name = "Type", value = "Message"},
{name = "Reference", value = tostring(ao.reference)}
{name = "Reference", value = referenceString}
}
}

Expand Down Expand Up @@ -176,14 +177,15 @@ function ao.send(msg)
end

-- Add a one-time callback that runs the user's (matching) resolver on reply
Handlers.once({From = from, ["X-Reference"] = ao.reference},
Handlers.once({From = from, ["X-Reference"] = referenceString},
resolver)
end

message.receive = function(...)
local from = message.Target
if select("#", ...) == 1 then from = select(1, ...) end
return Handlers.receive({From = from, ["X-Reference"] = ao.reference})
return
Handlers.receive({From = from, ["X-Reference"] = referenceString})
end

return message
Expand Down
Loading

0 comments on commit ac2ca70

Please sign in to comment.