Awaiting multiple Jimp page creation before running final function
See original GitHub issueI have two images that I’m adding text to, and then after that I have a function that converts those images to PDF format. I’ve tested the PDF generator, and that seems to be fine.
I attempted to emulate the syntax shown in #463 while editing each file. I load a Promise.all with the file and font, and then make my changes. However, I’m getting the following error:
TypeError: image.print is not a function
Two questions: Why am I getting the type error? What’s the best way to fix? What’s the proper way to pass all the functions in, await for them to completed, and then advance to final step?
exports.generate = (params) => {
// Params: id,
//
checkDirectory('./cache/' + params.order_id)
return Promise.all([
Jimp.read("./template_docs/file1.png"),
Jimp.loadFont(Jimp.FONT_SANS_32_BLACK)
]).then((image, font) => {
image.print(font, 628, 205, "" + params.first_value);
// phone
image.print(font, 830, 260, "" + params.second_value);
image.write('./cache/' + params.order_id + "/send1.png")
})
.then(function(){
return Promise.all([
Jimp.read("./template_docs/file2.png"),
Jimp.loadFont(Jimp.FONT_SANS_32_BLACK)
]).then((image, font) => {
// date
image.print(font, 480, 200, getDate());
return image.write('./cache/' + params.order_id + "/send2.png")
})
}).then(function() {
setTimeout(convertImagesToPDF({"input": [
"./cache/" + params.order_id + "/send1.png",
"./cache/" + params.order_id + "/send2.png"
], "output": "./cache/" + params.order_id + "/to_sign.pdf"
}), 10000);
}).catch(err => {
console.log(err)
})
}
Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Comments:9
Top Results From Across the Web
In JavaScript, does using await inside a loop block the loop?
The await keyword means to wait until this value (or error) has been finalized. So from the perspective of the running function, it...
Read more >Multiprocessing Pool Wait For All Tasks To Finish in Python
You can wait for tasks issued to the multiprocessing pool to complete by calling AsyncResult.wait() or calling Pool.join().
Read more >JavaScript — from callbacks to async/await - freeCodeCamp
Before the code executes, var and function declarations are “hoisted” to the top of their scope. This is an example of a synchronous...
Read more >How JavaScript works: Event loop and the rise of Async ...
A simple way of “waiting” for an asynchronous function to return its result is to use a function called callback: Just a note:...
Read more >Concurrency and async / await - FastAPI
You can only use await inside of functions created with async def . ... of parallelism and multiprocessing (having multiple processes running in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
when #486 merges it will be a lot easier since you can have
write
return promises but for now@hipstersmoothie Thank you for all your help!