Get Concurrency by Tutorials Second Edition Multithreading in Swift With GCD and Operations Tutorial Team PDF Ebook With Full Chapters Now
Get Concurrency by Tutorials Second Edition Multithreading in Swift With GCD and Operations Tutorial Team PDF Ebook With Full Chapters Now
com
https://textbookfull.com/product/concurrency-by-tutorials-
second-edition-multithreading-in-swift-with-gcd-and-
operations-tutorial-team/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/design-patterns-by-tutorials-third-
edition-learning-design-patterns-in-swift-raywenderlich-tutorial-team/
textboxfull.com
https://textbookfull.com/product/ios-11-by-tutorials-learning-the-new-
ios-apis-with-swift-4-1st-edition-the-raywenderlich-tutorial-team/
textboxfull.com
https://textbookfull.com/product/rxswift-reactive-programming-with-
swift-third-edition-raywenderlich-tutorial-team/
textboxfull.com
Server Side Swift with Vapor Building Web APIs and Web
Apps in Swift 3rd Edition Raywenderlich.Com Tutorial Team
https://textbookfull.com/product/server-side-swift-with-vapor-
building-web-apis-and-web-apps-in-swift-3rd-edition-raywenderlich-com-
tutorial-team/
textboxfull.com
Machine Learning by Tutorials Beginning Machine Learning
for Apple and iOS First Edition Raywenderlich Tutorial
Team
https://textbookfull.com/product/machine-learning-by-tutorials-
beginning-machine-learning-for-apple-and-ios-first-edition-
raywenderlich-tutorial-team/
textboxfull.com
https://textbookfull.com/product/ios-apprentice-eighth-edition-
beginning-ios-development-with-swift-and-uikit-raywenderlich-tutorial-
team/
textboxfull.com
https://textbookfull.com/product/design-patterns-by-tutorials-
learning-design-patterns-in-swift-4-2-joshua-greene/
textboxfull.com
https://textbookfull.com/product/core-data-by-tutorials-aaron-douglas/
textboxfull.com
https://textbookfull.com/product/simulations-in-swift-5-design-and-
implement-with-swift-playgrounds-beau-nouvelle/
textboxfull.com
Concurrency by Tutorials
Concurrency by Tutorials
By Scott Grosch
Notice of Rights
All rights reserved. No part of this book or corresponding materials (such as text,
images, or source code) may be reproduced or distributed by any means without prior
written permission of the copyright owner.
Notice of Liability
This book and all corresponding materials (such as source code) are provided on an
“as is” basis, without warranty of any kind, express of implied, including but not
limited to the warranties of merchantability, fitness for a particular purpose, and
noninfringement. In no event shall the authors or copyright holders be liable for any
claim, damages or other liability, whether in action of contract, tort or otherwise,
arising from, out of or in connection with the software or the use of other dealing in
the software.
Trademarks
All trademarks and registered trademarks appearing in this book are the property of
their own respective owners.
raywenderlich.com 2
Concurrency by Tutorials
raywenderlich.com 3
Concurrency by Tutorials
raywenderlich.com 4
Concurrency by Tutorials
raywenderlich.com 5
Concurrency by Tutorials
raywenderlich.com 6
Concurrency by Tutorials
raywenderlich.com 7
A About the Cover
Our usual experience when looking at an animal is to see the creature and know,
clearly, how its body is assigned and what each of its parts does — two legs for
walking, two ears for hearing, a mouth for eating, gills for breathing, one brain for
thinking.
Everything about the starfish is in multitudes that aren't always obvious to our eye:
five–50 arms, a mouth with five jaws, a eyespot on each arm with 80–100 ocelli, a
decentralized respiratory and central nervous system, a three-ringed circulatory
system, a common “mouth” used both in consuming and excreting, and tubed “feet”
that assist with sensing, moving and breathing.
If you find yourself on the east coast of the continental Americas, especially the
Caribbean, keep an eye out for a relatively small, impossibly purple seastar with
brilliant orange edges.
raywenderlich.com 8
Concurrency by Tutorials About the Cover
Dedications
"This book is dedicated to my wife and daughter, as well as to
my parents who always made sure a good education was a
priority."
— Scott Grosch
raywenderlich.com 9
Concurrency by Tutorials About the Cover
Shai Mishali is the Final Pass Editor of this book. He's the iOS
Tech Lead for Gett, the global on-demand mobility company; as
well as an international speaker, and a highly active open-source
contributor and maintainer on several high-profile projects -
namely, the RxSwift Community and RxSwift projects. As an avid
enthusiast of hackathons, Shai took 1st place at BattleHack Tel-
Aviv 2014, BattleHack World Finals San Jose 2014, and Ford's
Developer Challenge Tel-Aviv 2015. You can find him on GitHub
and Twitter @freak4pc.
Manda Frederick is the editor of this book. She has been involved
in publishing for over 10 years through various creative,
educational, medical and technical print and digital publications,
and is thrilled to bring her experience to the raywenderlich.com
family as Managing Editor. In her free time, you can find her at the
climbing gym, backpacking in the backcountry, hanging with her
dog, working on poems, playing guitar and exploring breweries.
raywenderlich.com 10
Concurrency by Tutorials About the Cover
raywenderlich.com 11
A Acknowledgements
Luke Freeman for coordinating and/or creating many of the images that you see in
this book.
raywenderlich.com 12
W What You Need
• A Mac running macOS Mojave (10.14) or later. Earlier versions might work, but
they're untested.
• Xcode 11 or later. Xcode is the main development tool for iOS. While earlier
versions of Xcode should work, the examples in this book have been specifically
tested on Xcode 11 and iOS 13. You can download the latest version of Xcode from
Apple’s developer site here: apple.co/2asi58y
If you want to try things out on a physical iOS device, you’ll need a developer
account with Apple, which you can obtain for free. However, all the sample projects
in this book will work just fine in the iOS Simulator bundled with Xcode, so the paid
developer account is completely optional.
raywenderlich.com 13
L Book License
• You are allowed to use and/or modify the source code in Concurrency by Tutorials in
as many apps as you want, with no attribution required.
• You are allowed to use and/or modify all art, images and designs that are included
in Concurrency by Tutorials in as many apps as you want, but must include this
attribution line somewhere inside your app: “Artwork/images/designs: from
Concurrency by Tutorials, available at www.raywenderlich.com”.
• The source code included in Concurrency by Tutorials is for your personal use only.
You are NOT allowed to distribute or sell the source code in Concurrency by
Tutorials without prior authorization.
• This book is for your personal use only. You are NOT allowed to sell this book
without prior authorization, or distribute it to friends, coworkers or students; they
would need to purchase their own copies.
All materials provided with this book are provided on an “as is” basis, without
warranty of any kind, express or implied, including but not limited to the warranties
of merchantability, fitness for a particular purpose and noninfringement. In no event
shall the authors or copyright holders be liable for any claim, damages or other
liability, whether in an action or contract, tort or otherwise, arising from, out of or in
connection with the software or the use or other dealings in the software.
All trademarks and registered trademarks appearing in this guide are the properties
of their respective owners.
raywenderlich.com 14
B Book Source Code &
Forums
The digital edition of this book also comes with free access to any future updates we
may make to the book!
The best way to get update notifications is to sign up for our monthly newsletter.
This includes a list of the tutorials that came out on raywenderlich.com that month,
any important news like book updates or new books, and a list of our favorite iOS
development links for that month. You can sign up here:
• www.raywenderlich.com/newsletter
https://store.raywenderlich.com/products/concurrency-by-tutorials-source-code
Forums
We’ve also set up an official forum for the book at forums.raywenderlich.com. This is
a great place to ask questions about the book or to submit any errors you may find.
raywenderlich.com 15
Concurrency by Tutorials Book Source Code & Forums
Buying the digital edition version of the book also has a few extra benefits: free
updates each time we update the book, access to older versions of the book, and you
can download the digital editions from anywhere, at anytime.
• https://store.raywenderlich.com/products/concurrency-by-tutorials.
And if you purchased the print version of this book, you’re eligible to upgrade to the
digital editions at a significant discount! Simply email [email protected] with
your receipt for the physical copy and we’ll get you set up with the discounted digital
edition version of the book.
raywenderlich.com 16
Section I: Getting Started with
Concurrency
In this part of the book, you’re going to learn about the basics of Concurrency. You're
going to learn what it is, what kind of problems it solves, and why would you even
use it?
Further, you will learn the basic pieces of which Concurrency comprises in iOS
development: Grand Central Dispatch and Operations.
This section will provide you with the foundational knowledge regarding
Concurrency, so be sure to read through! The upcoming sections will dive much
deeper into each of these concepts individually.
Chapter 1: Introduction: Get a quick overview of what concurrency is and why you
might want to use it.
raywenderlich.com 17
1 Chapter 1: Introduction
Performance. Responsiveness. They’re not sexy tasks. When done properly, nobody is
going to thank you. When done incorrectly, app retention is going to suffer and you’ll
be dinged during your next yearly performance review.
There are a multitude of ways in which an app can be optimized for speed,
performance and overall responsiveness. This book will focus on the topic of
concurrency.
What is concurrency?
Wikipedia defines concurrency as "the decomposability property of a program,
algorithm, or problem into order-independent or partially-ordered components or
units." What this means is looking at the logic of your app to determine which pieces
can run at the same time, and possibly in a random order, yet still result in a correct
implementation of your data flow.
Moderns devices almost always have more than a single CPU, and Apple’s iPhones
have been dual core since 2011. Having more than one core means they are capable
of running more than a single task at the same time. By splitting your app into
logical "chunks" of code you enable the iOS device to run multiple parts of your
program at the same time, thus improving overall performance.
raywenderlich.com 18
Concurrency by Tutorials Chapter 1: Introduction
Scrolling through a table of images is one of the more common situations wherein
the end user will be impacted by the lack of concurrency. If you need to download an
image from the network, or perform some type of image processing before displaying
it, the scrolling will stutter and you’ll be forced to display multiple "busy" indicators
instead of the expected image.
A beneficial side effect to using concurrency is that it helps you to spend a bit more
time thinking about your app’s overall architecture. Instead of just writing massive
methods to "get the job done" you’ll find yourself naturally writing smaller, more
manageable methods that can run concurrently.
Tasks which access different resources, or read-only shared resources, can all be
accessed via different threads to allow for much faster processing.
This book will focus on the two main ways that iOS provides you with the ability to
run code concurrently. The first section on Grand Central Dispatch will cover the
common scenarios where you will find yourself being able to implement concurrency.
You’ll learn how to run tasks in the background, how to group tasks together and
how to handle restricting the number of tasks that can run at once. By the end of the
first section you’ll also have a strong grasp of the dangers of concurrency and how to
avoid them.
In the second section you’ll focus on the Operation class. Built on top of Grand
Central Dispatch, operations allow for the handling of more complex scenarios such
as reusable code to be run on a background thread, having one thread depend on
another, and even canceling an operation before it’s started or completed.
raywenderlich.com 19
Concurrency by Tutorials Chapter 1: Introduction
Most modern programming languages provide for some form of concurrency and
Swift is of course no exception. Different languages use widely different mechanisms
for handling concurrency. C# and Typescript, for example use an async/await pattern,
whereas Swift uses closures to handle what runs on another thread. Swift 5 originally
had plans to implement the more common async/await pattern but it was removed
from the specification until the next release.
raywenderlich.com 20
2 Chapter 2: GCD &
Operations
There are two APIs that you'll use when making your app concurrent: Grand Central
Dispatch, commonly referred to as GCD, and Operations. These are neither
competing technologies nor something that you have to exclusively pick between. In
fact, Operations are built on top of GCD!
raywenderlich.com 21
Concurrency by Tutorials Chapter 2: GCD & Operations
While GCD uses threads in its implementation, you, as the developer, do not need to
worry about managing them yourself. GCD’s tasks are so lightweight to enqueue that
Apple, in its 2009 technical brief on GCD, stated that only 15 instructions are
required for implementation, whereas creating traditional threads could require
several hundred instructions.
All of the tasks that GCD manages for you are placed into GCD-managed first-in,
first-out (FIFO) queues. Each task that you submit to a queue is then executed
against a pool of threads fully managed by the system.
Note: There is no guarantee as to which thread your task will execute against.
Note: It’s important to keep in mind that, while the queues are FIFO based,
that does not ensure that tasks will finish in the order you submit them. The
FIFO procedure applies to when the task starts, not when it finishes.
raywenderlich.com 22
Concurrency by Tutorials Chapter 2: GCD & Operations
In general, you'll want to take any long-running non-UI task that you can find and
make it run asynchronously in the background. GCD makes this very simple via
closures with a few lines of code, like so:
DispatchQueue.main.async {
// Update the UI here
}
}
You'll learn all about DispatchQueue in Chapter 3, "Queues & Threads." In general,
you create a queue, submit a task to it to run asynchronously on a background
thread, and, when it’s complete, you delegate the code back to the main thread to
update the UI.
Note: While you can tell iOS that you'd like to use a concurrent queue,
remember that there is no guarantee that more than one task will run at a
time. If your iOS device is completely bogged down and your app is competing
for resources, it may only be capable of running a single task.
raywenderlich.com 23
Concurrency by Tutorials Chapter 2: GCD & Operations
In other words, a task being synchronous or not speaks to the source of the task.
Being serial or concurrent speaks to the destination of the task.
Operations
GCD is great for common tasks that need to be run a single time in the background.
When you find yourself building functionality that should be reusable — such as
image editing operations — you will likely want to encapsulate that functionality
into a class. By subclassing Operation, you can accomplish that goal!
Operation subclassing
Operations are fully-functional classes that can be submitted to an
OperationQueue, just like you'd submit a closure of work to a DispatchQueue for
GCD. Because they’re classes and can contain variables, you gain the ability to know
what state the operation is in at any given point.
• isReady
• isExecuting
• isCancelled
• isFinished
Unlike GCD, an operation is run synchronously by default, and getting it to run
asynchronously requires more work. While you can directly execute an operation
yourself, that’s almost never going to be a good idea due to its synchronous nature.
You'll want to get it off of the main thread by submitting it to an OperationQueue so
that your UI performance isn’t impacted.
Bonus features
But wait, there’s more! Operations provide greater control over your tasks as you can
now handle such common needs as cancelling the task, reporting the state of the
raywenderlich.com 24
Concurrency by Tutorials Chapter 2: GCD & Operations
BlockOperation
Sometimes, you find yourself working on an app that heavily uses operations, but
find that you have a need for a simpler, GCD-like, closure. If you don’t want to also
create a DispatchQueue, then you can instead utilize the BlockOperation class.
Note: Block operations run concurrently. If you need them to run serially,
you'll need to setup a dispatch queue instead.
If you’re just working with methods or chunks of code that need to be executed, GCD
is a fitting choice. If you’re working with objects that need to encapsulate data and
functionality then you’re more likely to utilize Operations. Some developers even go
to the extreme of saying that you should always use Operations because it’s built on
top of GCD, and Apple’s guidance says to always use the highest level of abstraction
provided.
At the end of the day, you should use whichever technology makes the most sense at
the time and provides for the greatest long-term sustainability of your project, or
specific use-case.
In the next chapter, you'll take a deep dive into how Grand Central Dispatch works,
learn about the difference between threads and queues, and identify some of the
complexities that can occur when implementing concurrency in your app.
raywenderlich.com 25
Concurrency by Tutorials Chapter 2: GCD & Operations
raywenderlich.com 26
Section II: Grand Central
Dispatch
In this section, you'll take a deep dive into Apple's most popular and easy-to-use
mechanism to write and manage concurrent tasks — Grand Central Dispatch. You'll
learn how to utilize queues and threads to control the execution of tasks in your app,
as well as how to group these tasks together. You'll also learn about common pitfalls
and dangers of using concurrency, and how you can avoid them.
Chapter 3: Queues & Threads: This chapter teaches you how to use a GCD queue
to offload work from the main thread. You'll also learn what a "thread" is.
Chapter 4: Groups & Semaphores: In the previous chapter you learned about how
queues work. In this chapter you'll expand that knowledge to learn how to submit
multiple tasks to a queue, which need to run together as a "group" so that you can be
notified when they have all completed. You'll also learn how to wrap an existing API
so that you can call it asynchronously.
Chapter 5: Concurrency Problems: By now you know how GCD can make your app
so much faster. This chapter will show you some of the dangers of concurrency if
you're not careful, and how to avoid them.
raywenderlich.com 27
3 Chapter 3: Queues &
Threads
Dispatch queues and threads have been mentioned a couple of times now, and you’re
probably wondering what they are at this point. In this chapter, you’ll get a much
deeper understanding of what Dispatch queue and Threads are, and how to best
incorporate them in your development workflow.
raywenderlich.com 28
Concurrency by Tutorials Chapter 3: Queues & Threads
Threads
You’ve probably heard the term multithreading at some point, yes? A thread is
really short for thread of execution, and it’s how a running process splits tasks
across resources on the system. Your iOS app is a process that runs multiple tasks by
utilizing multiple threads. You can have as many threads executing at once as you
have cores in your device’s CPU.
There are many advantages to splitting your app’s work into multiple threads:
• Faster execution: By running tasks on threads, it’s possible for work to be done
concurrently, which will allow it to finish faster than running everything serially.
Sounds great, right? More cores, more threads, faster app. I bet you’re ready to learn
how to create one, right? Too bad! In reality, you should never find yourself needing
to create a thread explicitly. The OS will handle all thread creation for you using
higher abstractions.
Apple provides the APIs necessary for thread management, but if you try to directly
manage them yourself, you could in fact degrade, rather than improve, performance.
The OS keeps track of many statistics to know when it should and should not allocate
or destroy threads. Don’t fool yourself into thinking it’s as simple as spinning up a
thread when you want one. For those reasons, this book will not cover direct thread
management.
Dispatch queues
The way you work with threads is by creating a DispatchQueue. When you create a
queue, the OS will potentially create and assign one or more threads to the queue. If
existing threads are available, they can be reused; if not, then the OS will create
them as necessary.
raywenderlich.com 29
Another Random Scribd Document
with Unrelated Content
fell around him. Suddenly he dropped, and hearts sank, thinking his
brief career ended; but he had only tripped over some obstacle. Often
he stumbled, sometimes he fell prostrate, but was quickly up again,
and finally disappeared limping, over the summit, and the Fifty-fifth
saw him no more for several months. As the boy sped away the last
time, the colonel shouted to him: “Bring calibre fifty-four.” General
Sherman’s letter to the War Department will tell the rest of the story.
I take the liberty of asking through you that something be done for a young lad
named Orion P. Howe, of Waukegan, Illinois, who belongs to the 55th Illinois, but
is at present from home, wounded. I think he is too young for West Point, but
would be the very thing for a midshipman.
When the assault at Vicksburg was at its height, on the 19th of May, and I was
in front near the road which formed my line of attack, this young man came up to
me wounded and bleeding, with a good, healthy boy’s cry: “General Sherman,
send some cartridges to Colonel Malmborg, the men are all out.” “What is the
matter, my boy?” “They shot me in the leg, sir, but I can go to the hospital. Send
the cartridges right away.” Even where we stood the shot fell thick, and I told him
to go to the rear at once, I would attend to the cartridges, and off he limped. Just
before he disappeared on the hill, he turned and called to me as loud as he could:
“Calibre 54.”
I have not seen the boy since, and his colonel gave me his address as above, and
says he is a bright, intelligent boy, with a fair preliminary education. What
arrested my attention there, was, and what renews my memory now, is, that one
so young, carrying a musket-ball wound through his leg, should have found his
way to me on that fatal spot, and delivered his message, not forgetting the very
important part even of the calibre of the musket, 54, which you know is an
unusual one. I’ll warrant the boy has in him the elements of a man, and I
commend him to the government as one worthy the fostering care of some of its
national institutions.
I am, with respect, your obedient servant,
W. T. Sherman,
Major-General Commanding.
BE PATRIOTIC.
It may be, my boy, that you will never be able to guide a regiment
of soldiers as did Nathan Beman, or carry cartridges as did young
Howe, but that is no reason why you should not be just as patriotic.
That boy who is law abiding, who opposes everything that tends to
undermine the national fabric, who decries Sabbath desecration, vile
language, bad literature, and all vices, is a patriot in the true sense of
the word, and can be relied upon in times of peace as well as war to
do his best for the country.
Be patriotic. Cultivate the spirit of admiration toward the national
flag. Dowered with priceless traditions its stars and stripes speak of
the sufferings of the past, the prosperity of the present, and the
glories of the future which shall attend the onward march of this
great Republic. It is the hallowed emblem of the world’s greatest
nation, and of its most resplendent civilization. Of Sherman it was
said that he never failed to salute the flag by taking off his hat in its
presence. That flag is the emblem of all we are and all we expect to
be.
“It floats that all the rights of men may every people bless
And God’s own kingdom walk the world in peace and righteousness.”
By Samuel Fallows
“Early let me seek Thy favor;
Early let me do Thy will;
Blessed Lord, and only Savior,
With Thy love my bosom fill;
Blessed Jesus,
Thou hast loved me, love me still.”
Having fairly embarked on the voyage which ceases not till the port
of eternity is reached, it is an exhibition of good seamanship to take
one’s bearings. By the log is estimated the progress of the vessel; by
the compass, the direction the ship is pursuing, and by the altitude of
the stars the latitude in which it is. In like manner the Moral
chapters indicate the progress boys should make; the Social, the
course they should take, and the Religious, the latitude in which they
should live. Of these the religious are the most essential, for a boy
cannot be truly religious without being moral and social.
When the Rebellion began a young man went to his mother and
said: “Mother, may I volunteer? I argue the matter in four plain
ways. First, my country needs me. Second, she calls me. Third, I am
able to go. Fourth, I am willing. This makes the duty very clear to me,
unless you interpose a veto, and I think you are too good a patriot to
do that.” She gave her consent, and before he departed, she said:
“You know, my son, how much I have wished to see you a Christian.
Now I want you to look at the claims of Jesus exactly as you have
looked at those of your country, simply and honestly, and see if those
same four plain propositions will not lead you into the service of
heaven.” “I’ll think of it, mother,” was his answer, and they parted.
He did not forget his promise. On his first Sabbath in camp he
resolutely set himself to the fulfilment of his mother’s request.
Remembering how he had argued duty to his country, he brought
before his mind in the same manner the subject of the divine claims
upon his heart and life. “Does Jesus want me? Does He call me? Am I
able to serve Him? Am I willing?” With an open Bible, the first three
questions were quickly answered. At the last one he hesitated, but
duty seemed so clear that he dared not falter, and falling on his knees
he gave himself to Christ. The next letter home announced him to be
a Christian soldier.
A CHRISTIAN.
Many names and titles are significant, but none means so much or
has so much honor attached to it as the word “Christian.” Young
said, “A Christian is the highest style of man.” A Christian is a Christ-
lover and a Christ-worshipper, because he sees God in Christ, and in
the God-man he sees the world’s Redeemer and his own personal
Saviour. He lives in the world, but is not of the world. While in the
world he blesses it by living a godly, upright life. His life work and
influence are a benediction to those among whom he moves. His
purpose is “not to make a living,” as Governor Russell, of
Massachusetts, used to say, “but to make a life.” He is far more
concerned about this than about dying. Death is the least of his
concerns. To live is Christ, and because of this, his life is proof of his
profession.
HOW TO BE A CHRISTIAN.
“REMEMBER.”
“Remember now thy Creator in the days of thy youth,” (Eccl. 12:1)
is the most important exhortation of the Old Testament. Remember
is just the opposite of forget, and the one to remember is the most
exalted and important in the universe, “thy Creator.” Remember His
Word and believe it, for the promise is: “He that heareth My Word
and believeth on Him that sent Me, hath everlasting life.” (John
5:24). Remember His work and accept it, for He was made to “sin for
us, Who knew no sin; that we might be made the righteousness of
God in Him.” (2 Cor. 5:21). Remember His love and return it, for
“herein is love, not that we loved God, but that He loved us,” (1 John
4:10) and “gave His only begotten Son, that whosoever believeth in
Him should not perish but have everlasting life.” (John 3:16).
Remember this Creator now. Only one time is mentioned in the
Scriptures at which eternal life is promised. Cowley sang of an
“everlasting now,” but there is no such time, and no wise boy desires
that there shall be. There is an eternity of the past, an eternity of the
future, but “now” is limited to now. “Behold, now is the accepted
time; behold, now is the day of salvation.” (2 Cor. 6:2). And this—
“Opportunity lost, however deplored
Is eternity gone and is never restored.”
By A. C. Lorimer, D. D.
When I was a youth, I loved to climb Arthur’s Seat early in the
morning, for the purpose of breathing the air borne to our inland
home from out the mighty seas; and so it is well for every lad each
day to seek the summit of highest faith, that he may hold
communion with God; that he may inhale something of the
atmosphere of eternal worlds.
It is said that Daniel opened his window when he prayed, toward
Jerusalem. It was doubtless that he might think of the hallowed city.
Better far, however, to open the windows of the soul toward heaven,
not merely that we may think of the hereafter, but that the invisible,
at the present moment, may stream into our being.
Prayer is the soul’s voice. It is the aspiration of the highest part of
man. It is the sublime confidence, that, though foreign, still it is
within the range of possibility to hold communion with the Creator
of us all. Every time we bend the knee before the Throne of Grace, we
declare our belief in our own God-likeness and in our indestructible
affinity for the divine. Therefore, pray, my boy, and keep on praying;
for it is the true Jacob’s ladder that will lead you, round by round, up
to the Everlasting Throne.
CHAPTER XXII
Be Prayerful
During the Civil War a dozen soldiers were playing cards one night
when one exclaimed: “What on earth was that?” Listening attentively
a moment, he heard a low, solemn voice, coming from the next tent,
occupied by several recruits, who had that day arrived in camp.
Accompanied by the others he approached the tent on tip-toe. “Boys,
he’s praying, or I’m a sinner!” he roared out. “Three cheers for the
parson!” shouted another man of the group as the prayer ended.
“You watch things for three weeks. I’ll show you how to take the
religion out of him,” said the first speaker, laughing. He was a large
burly fellow, prominent in mischief. The recruit was a slight, pale-
faced boy. During the next three weeks the latter was the butt of the
camp. Then several of the boys, conquered by the lad’s gentle
patience and uniform kindness, begged the others to stop annoying
him. “Oh, the little ranter is no better than the rest of us!” answered
the ringleader. “When we get under fire, you’ll see him run. These
pious folk don’t like the smell of gunpowder. I’ve no faith in their
religion.”
In a few weeks, the regiment broke camp, marched toward
Richmond, entered the Wilderness and engaged in that fearful battle.
The company to which the young recruit belonged had a desperate
struggle. The brigade was driven back, and when the line was formed
behind the breastworks they had built in the morning, he was
missing. When last seen, he was surrounded by enemies, fighting
desperately. At his side was the brave fellow who had made the poor
lad a constant object of ridicule. Both were given up as lost. Suddenly
the big man was seen tramping through the underbrush, bearing the
dead body of the boy. Reverently he laid the corpse down, saying as
he wiped the blood from his own face: “Boys, I couldn’t leave him
behind, he fought so. I thought he deserved a decent burial.”
During a lull in the battle the men dug a shallow grave and
tenderly laid him to rest. Then, as one was cutting the name and
regiment upon a board, the big man said, with a husky voice, “I guess
you’d better put the words ‘Praying soldier’ in somewhere. He
deserves the title, and maybe it’ll console him for our abuse.”
There was not a dry eye among those rough men as they stuck the
rudely carved board at the head of the grave. “Well,” said one, “he
was a praying Christian soldier if ever there was one! And,” turning
to the ringleader, “he didn’t run, did he, when he smelt gunpowder?”
“Run!” answered the big man, his voice tender with emotion. “Why,
he didn’t budge an inch! But what’s that to standing for weeks our
fire like a man, and never sending a word back! He just stood by his
flag and let us pepper him, he did; and boys, I have made up my
mind if prayer will make a man as bold, as loving, as forgiving, as
good, as it did that boy, I’m going to resort to it. It did him good and
it’ll do me good,” and as the other fellows bent their heads he prayed
for forgiveness and salvation, at the close of which the others said,
“Amen!”
HOW TO PRAY.
Prayer is a blessed privilege, a vital necessity, an imperative duty,
but many there are who do not know how to pray. A mere repetition
of words or reading prayers is not prayer. Prayer may be a sigh, a
tear, a groan, a bungling utterance, “a true wish” as Phillips Brooks
used to say, “sent God-ward.” It is—
“the soul’s sincere desire
Uttered or unexpressed.
The motive of a hidden fire
That kindles in the breast.”
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com