Git Product home page Git Product logo

Comments (4)

vrld avatar vrld commented on July 21, 2024

What is the error message?

from hump.

vrld avatar vrld commented on July 21, 2024

Can you please give more information? What did you expect and what did you get instead? Your example ...

signal.register("slot", function()
  print("Foo")
  signal.register("slot", function() print("Bar") end)
  print("Baz")
end)

signal.emit("slot")

... Works as expected:

Foo
Baz
Bar

The timer example also works as expected:

timer.after(1, function()
  print("Foo")
  timer.after(1, function()
    print("Bar")
  end)
end)

timer.update(1) --> Foo
timer.update(1) --> Bar

from hump.

ka7713 avatar ka7713 commented on July 21, 2024
signal = require("signal")

function register()
	signal.register(1, function()
	  print("Foo")
	  signal.register(1, function() print("Bar") end)
	  print("Baz")
	end)
end

for i=1, 10 do
	register()
	signal.emit(1)
	signal.clear(1)
	print("---")
end

(LuaJIT 2.0.5)

luajit.exe test.lua
Foo
Baz -- <<--- I think this is right. Because Bar is register after emit.
---
Foo
Baz
---
Foo
Baz
---
Foo
Baz
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
---
Foo
Baz
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---

(lua 5.1.4)

lua5.1.exe test.lua
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---

(I'm sorry, My English is not good)

from hump.

ka7713 avatar ka7713 commented on July 21, 2024

more sample

signal = require("signal")

function test1(mode)
	print("Foo")
	signal.register(1, function() print("Bar") end)
	print("Baz")
end

function register()
	signal.register(1, test1)
	signal.register(1, function() end)
	signal.register(1, function() end)
	signal.register(1, function() end)
end

for i=1,10 do
	register()
	signal.emit(1)
	signal.clear(1)
	print("---")
end
luajit.exe test.lua
Foo
Baz
Bar
Foo --<< call twice
Baz
---
Foo
Baz
Foo
Baz
---
Foo
Baz
Bar
---
Foo
Baz
Foo
Baz
---
Foo
Baz
Foo
Baz
---
Foo
Baz
Bar
Foo
Baz
---
Foo
Baz
Bar
Foo
Baz
---
Foo
Baz
Foo
Baz
---
Foo
Baz
Foo
Baz
---
Foo
Baz
Bar
Foo
Baz
---
lua5.1.exe test.lua
Foo
Baz
Bar
---
Foo --<<
Baz
---
Foo --<<
Baz
---
Foo
Baz
Bar
---
Foo --<<
Baz
---
Foo
Baz
Bar
---
Foo
Baz
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo --<<
Baz
---

Timer

timer = require("timer")

function register()
	timer.after(0.5, function() 
		print("Foo")
		-- Bar total 1 second
		timer.after(0.5, function() print("Bar") end)
		print("Baz")
	end)
	timer.after(0.5, function() end)
	timer.after(0.5, function() end)
	timer.after(0.5, function() end)
end

for i=1,10 do
	register()
	timer.update(0.5)
	timer.clear()
	print("---")
end
luajit.exe test3.lua
Foo
Baz
Bar -- Bar 1 sec but call 0.5 sec
---
Foo
Baz
Bar
---
Foo
Baz
---
Foo
Baz
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
lua5.1.exe test3.lua
Foo
Baz
---
Foo
Baz
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---
Foo
Baz
Bar
---

from hump.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.