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).
Ultimate Guide to Types in TypeScript
TypeScript is a strongly typed language built on top of Javascript. As such, types have to be defined in TypeScript when we write our code, rather than inferred as they normally are in Javascript.
In this guide, we'll be diving into how types work in TypeScript, and how you can make the most of them. If you're totally new to TypeScript, start with our guide on making your first TypeScript project.
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.
Async Programming Java: Part II
This is part II of my previous article Async Programming in Java: Part I. We have seen the various ways to create threads and run them. Java Executor framework helps us to create, run and manage the threads.
We will look deep at how the executor service works internally and various factory methods provided by the Executor framework.
Enabling the Transportation of the Future With QA
'Connected' is the way of modern society and that is how things are going to be in the years to come.
Certainly, the internet has been the pioneer of this connected revolution, and look how far we have come.
How to Create Controllable Futures in Scala
xxxxxxxxxx
val myFuture = Future {
// you have no future, you are DOOMED!
42
// JK.
}
You know the value inside will be evaluated on "some" thread, at "some" point in time, without your control.
The Scenario
xxxxxxxxxx
def gimmeMyPreciousValue(yourArg: Int): Future[String]
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:
xxxxxxxxxx
object MyService {
def produceThePreciousValue(theArg: Int): String = "The meaning of your life is " + (theArg / 42)
def submitTask[A](actualArg: A)(function: A => Unit): Boolean = {
// send the function to be evaluated on some thread, at the discretion of the scheduling logic
true
}
}
The service has two API methods:
-
A "production" function that is completely deterministic.
-
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.
xxxxxxxxxx
def gimmeMyPreciousValue(yourArg: Int): Future[String] = Future {
MyService.produceThePreciousValue(yourArg)
}
because spawning up the thread responsible for evaluating the production function is not up to you.
The Solution
xxxxxxxxxx
// create an empty promise
val myPromise = Promise[String]()
// extract its future
val myFuture = myPromise.future
// do your thing with the future, assuming it will be filled with a value at some point
val furtherProcessing = myFuture.map(_.toUpperCase())
Then pass that promise to someone else, perhaps an asynchronous service:
xxxxxxxxxx
val asyncCall(promise: Promise[String]): Unit = {
promise.success("Your value here, your majesty")
}
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
def gimmeMyPreciousValue(yourArg: Int): Future[String] = {
// create promise now
val thePromise = Promise[String]()
// submit a task to be evaluated later, at the discretion of the service
// note: if the service is not on the same JVM, you can pass a tuple with the arg and the promise so the service has access to both
MyService.submit(yourArg) { x: Int =>
val preciousValue = MyService.producePreciousValue(x)
thePromise.success(preciousValue)
}
// return the future now, so it can be reused by whoever's consuming it
thePromise.future
}
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.
failure
,
trySuccess
/
tryFailure
and more.
The Top Books a Junior Developer Must Read in 2020
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
Executive Insights on the Current State of the Java Ecosystem
This article is featured in the new DZone Guide to Java: New Developments & Features. Get your free copy for insightful articles, industry stats, and more!
To understand the current and future state of the Java ecosystem, we reached out to our community for their insights.