|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
706 bytes
|
| Line | |
|---|
| 1 | 'use strict'
|
|---|
| 2 |
|
|---|
| 3 | exports.fromCallback = function (fn) {
|
|---|
| 4 | return Object.defineProperty(function (...args) {
|
|---|
| 5 | if (typeof args[args.length - 1] === 'function') fn.apply(this, args)
|
|---|
| 6 | else {
|
|---|
| 7 | return new Promise((resolve, reject) => {
|
|---|
| 8 | args.push((err, res) => (err != null) ? reject(err) : resolve(res))
|
|---|
| 9 | fn.apply(this, args)
|
|---|
| 10 | })
|
|---|
| 11 | }
|
|---|
| 12 | }, 'name', { value: fn.name })
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | exports.fromPromise = function (fn) {
|
|---|
| 16 | return Object.defineProperty(function (...args) {
|
|---|
| 17 | const cb = args[args.length - 1]
|
|---|
| 18 | if (typeof cb !== 'function') return fn.apply(this, args)
|
|---|
| 19 | else {
|
|---|
| 20 | args.pop()
|
|---|
| 21 | fn.apply(this, args).then(r => cb(null, r), cb)
|
|---|
| 22 | }
|
|---|
| 23 | }, 'name', { value: fn.name })
|
|---|
| 24 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.