summaryrefslogtreecommitdiff
path: root/src/lib/util.js
blob: a4e0025c48711270e443a1b979d6d971b0613a07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module.exports = {
    timestamp() {
        return parseInt(+(new Date())/1000)
    },

    isNumeric(n) {
        return !isNaN(parseFloat(n)) && isFinite(n)
    },

    /**
     * Creates a Promise that can be resolved or rejected from the outside
     *
     * @param {Function} abortCallback
     * @return {Promise}
     */
    createCallablePromise(abortCallback = null) {
        let promise, resolve, reject
        promise = new Promise(function(_resolve, _reject) {
            resolve = _resolve
            reject = _reject
        })
        promise.resolve = function(result) {
            resolve(result)
        }
        promise.reject = function(result) {
            reject(result)
        }
        return promise
    }
}