Skip to content

Commit

Permalink
add resemble pool
Browse files Browse the repository at this point in the history
  • Loading branch information
winsonwq committed Jun 7, 2014
1 parent c52fadc commit 401d26c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/comparison.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class Comparison
@compare: (fileAData, fileBData, callback) ->
defer = Q.defer()
promise = defer.promise.then callback
resemble.compare dataUrlHelper.toDataURL(fileAData), dataUrlHelper.toDataURL(fileBData), (data) ->

r = resemble.get()
r.running = true
r.compare dataUrlHelper.toDataURL(fileAData), dataUrlHelper.toDataURL(fileBData), (data) ->
r.running = false
defer.resolve data

promise
Expand Down
19 changes: 18 additions & 1 deletion src/resemble.coffee
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
Resemble = require 'phantomjs-resemble'
module.exports = new Resemble()
resemblePool = []

module.exports =

get: ->
resembles = (r for r in resemblePool when r.running isnt true)
if resembles[0]?
return resembles[0]
else
r = new Resemble()
r.running = false
resemblePool.push r
return r

exit: ->
for r in resemblePool
r.exit()
r.running = false

0 comments on commit 401d26c

Please sign in to comment.