Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
This package provides an async timer object, that should have been part of batteries.
Sometimes, you need a way to make something happen over and over again at certain times, like updating information or sending reminders. That's where Async Timer comes in. It lets you set up these repeated actions easily.
This package is particularly useful for tasks like automatically updating caches in the background without disrupting the primary application's workflow.
stop()
/cancel()
method OR it can stop automatically on an awaitable resolving (the cancel_aws
constructor artument)mock_async_timer.MockTimer
class with mocked sleep function to aid in your testingThis snippet starts fastapi webserver with the refresh_db
function being executed every 5 seconds, refresing a shared DB_CACHE
object.
import contextlib
import time
import uvicorn
from fastapi import FastAPI
import async_timer
DB_CACHE = {"initialised": False}
async def refresh_db():
global DB_CACHE
DB_CACHE |= {"initialised": True, "cur_value": time.time()}
@contextlib.asynccontextmanager
async def lifespan(_app: FastAPI):
async with async_timer.Timer(delay=5, target=refresh_db) as timer:
await timer.wait(hit_count=1) # block until the timer triggers at least once
yield
app = FastAPI(lifespan=lifespan)
@app.get("/")
async def root():
return {"message": "Hello World", "db_cache": DB_CACHE}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
import async_timer
timer = async_timer.Timer(12, target=lambda: 42)
timer.start()
val = await timer.join() # `val` will be set to 42 after 12 seconds
# Async for loop example
import async_timer
import time
with async_timer.Timer(14, target=time.time) as timer:
async for time_rv in timer:
print(f"{time_rv=}") # Prints current time every 14 seconds
FAQs
The missing Python async timer.
We found that async-timer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.