GithubHelp home page GithubHelp logo

timeout's People

Contributors

marcuscalidus avatar rommelsantor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

timeout's Issues

switching to Typescript?

Hi @rommelsantor ,

I know this could be a controversial topic.

What do you think about switching this library to Typescript?

I am using your library in several larger inhouse projects. For that I have had to expand some functionality. I would love to do it by overriding. But that's not so safe if there is no possibility for type checking in place (in case the backend changes). Therefore I had to fork your project https://github.com/MarcusCalidus/Timeout.git

If you are into the idea of moving to Typescript I'd gladly offer my help for translating the library.

Cannot import Timeout through HTML. [ReferenceError: exports is not defined]

Hello,

I tried using this HTML to import the code:

<script crossorigin="anonymous" src="https://cdn.jsdelivr.net/npm/[email protected]/index.js">var exports = {};</script>

But it gives me a ReferenceError as the title says above. From what I read, I believe I need to have CommonJS library imported.

I want to use this library for my repository that is hosted on GitHub Pages. Can you help me?

No functions are found

When I try using any of the functions:
Timeout.set(), Timeout.remaining(), Timeout.anything()
it says that the function is undefined.,
image
Version:

  • tried on latest 2.4.0
  • tried on 2.3.1
    none of which worked.
    It's a major bug and I need the functionality that this module provides!

give instantiate an optional key as well

I know in the documentation it says that this "defeats the purpose of instantiate", however, the good thing about this lib is that key feature which makes it easier to keep track of all timeouts from anywhere. I think this option will make it possible to the following:

let t = timeout.instantiate('huga', ()=>console.log('blah'), 3000);
// ... do things with t
// this should still work as usual, but we can't get this from anywhere else since there is no key
let toto = timeout.instantiate(()=>console.log('blah'), 3000);

somewhere else where there is no access to t

console.log('t remaining time: ', timeout.remaining('huga'));
// or get and use the instance here
let tt = timeout('huga');
tt.restart()

Add ability to invoke timed out function immediately

So I'm a little new at this, not sure what to expect, but it would be cool if there was a public method for invoking (and optionally clearing immediately?) the timeout. Obviously the function can be stored some where and later triggered manually & then the timeout cleared, but poking around in the code shows an invoke method of sorts already exists, it's just not public.

Something like this maybe? ๐Ÿคทโ€โ™‚

  const invoke = key => {
    if (!pending(key)) { return; }
    metadata[key].func(...metadata[key].params)
    clear(key)
  }

Install via npm/yarn

Would you accept a PR that publishes this to npm for easy installation? I could convert this to esnext modules, or I could add that as an option. The latter is more work. ๐Ÿ˜›

reset or renew a timeout

This enables rekindling a dead timeout as if it's new

timeout.set('huga', ()=>console.log('huga done!'), 5000);
// ... later on after the whole thing is dead, maybe after 12000ms
timeout.renew('huga')
// if this was instantiated to t...
t.renew()

That will just reinstantiate the timeout and replace it in mem.

optionally we could set new delay

timeout.renew('huga', 400)
// if this was instantiated to t...
t.renew(400)

Ability to reference a specific timeout and calls functions on it

This package looks really good in terms of functionality. One area I see for improvement is the ability to reference a timeout itself as a variable and call all available functions on the timeout.
Having that ability will allow to create timers and pass them to different areas of my code that might want to know about it. Currently it is difficult to get status on a timeout if it was created in one file and then passed into another.

Here is an example of what I would like to see

const Timeout = require('smart-timeout');

let newTimeout = Timeout(function(){ return 'does stuff'}, 1000);
newTimeout.remaining();
newTimeout.executed();
etc...

Do you have additional thoughts on this?

not repeat

Timeout called my callback only once !!
Timeout.set("cpu_info", getInformation, millisecs = 9000, ["cache", "voltage", "flags"]);

support for .elapsed ()

The remaining function is a God-sent, I think another one is missing, which I have been trying to use:

timeout.set('huga', ()=>console.log('huga done!'), 5000);
// ... later on just like remaining()...
timeout.elapsed('huga')
// => 3384

this is just the opposite of remaining

How do i pass a parameter to Timeout.set()

How do i pass a parameter(s) to Timeout.set()
e.g
in setTimeout(myfunction,10,param1,param2);

I have tried below but not working.
Timeout.set('key',myfunction,10,param1,param2)

instance information via .info

There is currently no way of getting information about the instance

timeout.set('huga', ()=>console.log('huga done!'), 5000);
// ... later we may want to know info about this timeout
timeout.info('huga')
// returns something like => { name: 'huga', cb ฦ’, delay: 5000}
// if this was instantiated to t...
t.info()

Restart

Hi,

Is there something in the pipeline to restart the timeout. My idea: I start a timeout for creating a screen saver after 5 seconds, but if anything is touched, clicked or similar, the timeout should be restarted.

Thanks,
Roland

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.