Future JavaScript: Temporal

I've written in the past about the many quirks of Javascript dates. The good news is that there are plans for an entirely new piece of Javascript functionality to clean up what Date() does wrong. That functionality is called Temporal. In this guide, we'll be covering why Temporal is better than Date(), and how to use it.

Support for Temporal

Temporal is currently a stage 3 proposal which means that although a large portion of its functionality is stable, there may be some changes in the future. As the specification is not stable yet, no browser or backend Javascript has implemented the temporal specification. If you want to try out Temporal today, you can try this polyfill (use with caution in production).

Future, A Token of Task Submission

Future, A Token of Task Submission

I believe, the title is very abstract but clearly explains the purpose. The concurrency package is the boss when it's come to asynchronous programming. Of course, this is the continuation of my previous articles on asynchronous programming.

We have seen creating Threads and make use of Executor Framework for the Thread management. Also, We look at how to submit a task and how is it processed internally in the executor. But we haven't seen how to check the status or getting the result etc.

Wearable Devices and Internet of Things: What The Future Holds

Is wearable tech still in its infancy?

Smartwatches and wearable tech are now on a different horizon. And, that’s possible because of how different technologies are working together to make them smarter. One such technology is the Internet of Things (IoT). It enables the devices to communicate and function through the network and make the best available resources and data.

How to Create Controllable Futures in Scala

This article is for the Scala programmer who has at least used or heard about Futures before. You can also find this over at the Rock the JVM blog or on YouTube in video form or embedded below:


In this article, I'm going to address the problem of "deterministic" Futures in Scala. You probably know by now that Futures are inherently non-deterministic, in the sense that if you create a Future
Scala

You know the value inside will be evaluated on "some" thread, at "some" point in time, without your control.

The Scenario

Here, I will speak to the following scenario which comes up often in practice. Imagine you're designing a function like this:
Scala

with the assumption that you're issuing a request to some multi-threaded service which, is getting called all the time. Let's also assume that the service looks like this:
Scala

The service has two API methods:
  1. A "production" function that is completely deterministic.
  2. A submission function that has a pretty terrible API because the function argument will be evaluated on one of the service's threads, and you can't get the returned value back from another thread's call stack.
Let's assume this important service is also impossible to change, for various reasons (API breaks, etc). In other words, the "production" logic is completely fixed and deterministic. However, what's not deterministic is when the service will actually end up calling the production function. In other words, you can't implement your function as:
Scala

because spawning up the thread responsible for evaluating the production function is not up to you.

The Solution

Introducing Promises — a "controller" and "wrapper" over a Future. Here's how it works. You create a Promise, get its Future and use it (consume it) with the assumption that it will be filled in later:
Scala

Then pass that promise to someone else, perhaps an asynchronous service:
Scala

And at the moment, the promise contains a value. Its future will automatically be fulfilled with that value, which will unlock the consumer.

How to Use it

For our service scenario, here's how we would implement our function:
Scala

We create a promise and then we return its future at the end for whoever wants to consume it. In the middle, we submit a function that will be evaluated at some point out of our control. At that moment, the service produces the value and fulfills the Promise, which will automatically fulfill the Future for the consumer.

This is how we can leverage the power of Promises to create "controllable" Futures, which we can fulfill at a moment of our choosing. The Promise class also has other methods, such as failure, trySuccess/ tryFailure and more.

I hope this was useful!

The Top Books a Junior Developer Must Read in 2020

Read on for book recommendations!

Whether you are new to the world of developing or are fairly experienced, you have probably realized at some point that focusing solely on your job isn’t the best way to build up your skill and knowledge. There are some excellent ways a developer can sharpen his skill set today; pair-programming, meetups, online courses, and mentors are all great, but sometimes a good old book might hold all the answers you need.

Agree? If so, keep reading for the top recommendations for a developer.

Why Time Dimension Is Vital in IoT and How a Rules Engine Can Reduce Complexity

The time dimension increases the complexity of application development for software developers that are building logic with conditional statements (rules) that need to change over time.

“Time is an observed phenomenon, by means of which human beings sense and record changes in the environment and in the universe. Time has been called an illusion, a dimension, a smooth-flowing continuum, and an expression of separation among events that occur in the same physical location.” — whatis.techtarget.com