codetiming icon indicating copy to clipboard operation
codetiming copied to clipboard

Instantiate and start timer on single line

Open Evidlo opened this issue 2 years ago • 0 comments

It would be helpful if there was a way to start the timer when it is instantiated, such as t = Timer().start() or t = Timer(now=True).

This can reduce the number of required lines from 3 to 2 which is nice when inserting many timers.

t = Timer().start()
# code block 1
t.stop()

t = Timer().start()
# code block 2
t.stop()

t = Timer().start()
# code block 3
t.stop()

To do this, either .start() would need to return self or a Timer.__post_init__ function would need to if self.now == True.

Evidlo avatar Feb 21 '24 01:02 Evidlo