aboutsummaryrefslogtreecommitdiff
path: root/sandbox/testAppNevena/Front/node_modules/@gar/promisify/README.md
diff options
context:
space:
mode:
authorDanijel Andjelkovic <adanijel99@gmail.com>2022-03-01 21:54:41 +0100
committerDanijel Andjelkovic <adanijel99@gmail.com>2022-03-01 21:54:41 +0100
commit6c8128f9fd5a5d0be115806c35a21b3d683df8d6 (patch)
treef46c2f6b3b9b294ff32bd75c08ccdc9e7a8cc4ef /sandbox/testAppNevena/Front/node_modules/@gar/promisify/README.md
parent2400b84e95913665da6279114168148444b8f9ab (diff)
parent7d3640f824f46490b47bd95f1c5a16644f712068 (diff)
Merge branch 'dev' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar into logo
Diffstat (limited to 'sandbox/testAppNevena/Front/node_modules/@gar/promisify/README.md')
-rw-r--r--sandbox/testAppNevena/Front/node_modules/@gar/promisify/README.md65
1 files changed, 65 insertions, 0 deletions
diff --git a/sandbox/testAppNevena/Front/node_modules/@gar/promisify/README.md b/sandbox/testAppNevena/Front/node_modules/@gar/promisify/README.md
new file mode 100644
index 00000000..465c546a
--- /dev/null
+++ b/sandbox/testAppNevena/Front/node_modules/@gar/promisify/README.md
@@ -0,0 +1,65 @@
+# @gar/promisify
+
+### Promisify an entire object or class instance
+
+This module leverages es6 Proxy and Reflect to promisify every function in an
+object or class instance.
+
+It assumes the callback that the function is expecting is the last
+parameter, and that it is an error-first callback with only one value,
+i.e. `(err, value) => ...`. This mirrors node's `util.promisify` method.
+
+In order that you can use it as a one-stop-shop for all your promisify
+needs, you can also pass it a function. That function will be
+promisified as normal using node's built-in `util.promisify` method.
+
+[node's custom promisified
+functions](https://nodejs.org/api/util.html#util_custom_promisified_functions)
+will also be mirrored, further allowing this to be a drop-in replacement
+for the built-in `util.promisify`.
+
+### Examples
+
+Promisify an entire object
+
+```javascript
+
+const promisify = require('@gar/promisify')
+
+class Foo {
+ constructor (attr) {
+ this.attr = attr
+ }
+
+ double (input, cb) {
+ cb(null, input * 2)
+ }
+
+const foo = new Foo('baz')
+const promisified = promisify(foo)
+
+console.log(promisified.attr)
+console.log(await promisified.double(1024))
+```
+
+Promisify a function
+
+```javascript
+
+const promisify = require('@gar/promisify')
+
+function foo (a, cb) {
+ if (a !== 'bad') {
+ return cb(null, 'ok')
+ }
+ return cb('not ok')
+}
+
+const promisified = promisify(foo)
+
+// This will resolve to 'ok'
+promisified('good')
+
+// this will reject
+promisified('bad')
+```