mirror of
https://github.com/zero-peak/ZeroOmega.git
synced 2025-01-23 15:28:12 -05:00
20 lines
583 B
CoffeeScript
20 lines
583 B
CoffeeScript
|
OmegaTarget = require('omega-target')
|
||
|
Promise = OmegaTarget.Promise
|
||
|
|
||
|
chromeApiPromisifer = (originalMethod) ->
|
||
|
return (args...) ->
|
||
|
new Promise (resolve, reject) =>
|
||
|
callback = (callbackArgs...) ->
|
||
|
if chrome.runtime.lastError?
|
||
|
return reject(chrome.runtime.lastError)
|
||
|
if callbackArgs.length <= 1
|
||
|
resolve(callbackArgs[0])
|
||
|
else
|
||
|
resolve(callbackArgs)
|
||
|
|
||
|
args.push(callback)
|
||
|
originalMethod.apply(this, args)
|
||
|
|
||
|
module.exports = (obj) ->
|
||
|
Promise.promisifyAll(Object.create(obj), {promisifier: chromeApiPromisifer})
|