/echoAtTime
- receives two parameters, time and message, and writes that message to the server console at the given time.
npm i
Start server:
REDIS_URL=redis://localhost:6379 PORT=3000 npm start
Send time in ISO format (new Date().toISOString()
) and message in json
format:
curl localhost:3000/echoAtTime -X POST -d '{"time": "2019-09-04T20:07:33.455Z", "message": "hello worlds"}'
-
A couple messages can be passed with the same time, so time field always modified with a suffix of a form
time^i
, wherei
is a counter. -
To represent
time
andmessage
dataHashes
redis data type was chosen, because of usage conviniance and speed. -
To write the message at the given time
setTimeout
used with a subtraction result between given and current time. This solution isn't perfect, but it is the best we can achive using built-inJavaScript
functions.