sushantpaudel / jimp-watermark

MIT License
21 stars 7 forks source link

Remove race condition on addWatermark. #1

Closed connorlurring closed 2 years ago

connorlurring commented 4 years ago

Await writeAsync to ensure write is complete before return.

gentechwork commented 4 years ago

@connorlurring Isn't writing an await with writeAsync and writing without an await with write the same? If it is not the same, could you elaborate? image

connorlurring commented 4 years ago

@sushantwork the write method is poorly named, it isn't synchronous. It accepts a second argument, which is a callback. This means we end up with a race condition where in the case of small images, the write happens fast enough that there is no issue, but in the case of large images, the method does not wait for the write to complete before returning as the callback is not blocking.

Using await and writeAsync we can ensure that the method waits for the write to complete before continuing.