Skip to content

coderaiser/echo-at-time

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Echo At Time Build Status

/echoAtTime - receives two parameters, time and message, and writes that message to the server console at the given time.

Install

npm i

Usage

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"}'

Decisions

  • A couple messages can be passed with the same time, so time field always modified with a suffix of a form time^i, where i is a counter.

  • To represent time and message data Hashes 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-in JavaScript functions.

About

print a message at a given time in the future

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published