lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Great solution!

On Thu, May 21, 2009 at 10:30 AM, Fabio Mascarenhas <mascarenhas@acm.org> wrote:
> Using http://alien.luaforge.net
>
> -----------------------
> require "alien"
>
> if alien.platform == "windows" then
>  local sleep = alien.kernel32.Sleep
>  sleep:types{ abi = "stdcall", ret = "void", "int" }
>  -- Windows' Sleep takes duration in ms
>  function _G.sleep(n) sleep(n * 1000) end
> else
>  local sleep = alien.default.sleep
>  sleep:types("void", "int")
>  function _G.sleep(n) sleep(n) end
> end
>
> -- now sleep for two seconds
> sleep(2)
> ----------------
>
> You could say this is overkill, of course. :-)
> --
> Fabio Mascarenhas
>
>
>
>
> On Thu, May 21, 2009 at 10:38 AM, Marco Antonio Abreu
> <mabreu.ti@gmail.com> wrote:
>> Hi. I were using something like this, os.time() instead o os.clock(), but it
>> uses much CPU to do nothing. In a case like mine, where the server is so
>> hard used by many process, it could be very bad for global performance.
>> tks
>> [],
>> Marco
>>
>>
>> On Wed, May 20, 2009 at 11:58 PM, RJP Computing <rjpcomputing@gmail.com>
>> wrote:
>>>
>>>
>>> On Wed, May 20, 2009 at 4:33 PM, Marco Antonio Abreu <mabreu.ti@gmail.com>
>>> wrote:
>>>>
>>>> Hi Guys,
>>>> I am writting a script to copy some data from one database to another,
>>>> this script will be running all the time, verifying if have something to
>>>> copy.
>>>> I need to wait for some seconds between two checks, to do not overload
>>>> the DB server or CPU.
>>>> How can I implement a function (or use if already has) to perform a
>>>> "sleep", to wait some (milli)seconds doing nothing.
>>>
>>> This is a Lua version and yes I know it is not a true Sleep because it
>>> uses CPU, but here you go:
>>>
>>> function Delay( seconds )
>>>      local start = os.clock()
>>>      while os.clock() - start < seconds do end
>>>  end
>>>
>>> Delay( .500 )
>>> --
>>> Regards,
>>> Ryan
>>
>>
>>
>>
>