Skip to content

Instantly share code, notes, and snippets.

Avatar
😇
No one.

Harshit Kaushik HarshitKaushik

😇
No one.
View GitHub Profile
@HarshitKaushik
HarshitKaushik / promises.md
Created Jun 13, 2018 — forked from domenic/promises.md
You're Missing the Point of Promises
View promises.md

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
    // the rest of your code goes here.
View getActivityTime.java
public static String getActivityTime(Date inputDate) {
Date currentDate = new Date();
Long currentTime = new Date().getTime();
Long inputTime = inputDate.getTime();
long timeRemaining = currentTime - inputTime;
long sec = (timeRemaining / 1000) % 60;
long min = (timeRemaining / (1000 * 60)) % 60;
long hours = (timeRemaining / (1000 * 60 * 60)) % 24;
You can’t perform that action at this time.