Skip to content

Commit

Permalink
actual examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Oct 10, 2015
1 parent 58fc052 commit 056c828
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
22 changes: 22 additions & 0 deletions examples/fs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*!
* then-callback <https://github.com/hybridables/then-callback>
*
* Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/

'use strict'

var fs = require('fs')
var path = require('path')
var redolent = require('redolent')
var readFile = redolent(fs.readFile)

var thenCallback = require('../index')
var promise = readFile(path.join(__dirname, '..', 'package.json'), 'utf8')
promise = thenCallback(promise)

promise.then(function (err, res) {
if (err) return console.error(err)
console.log(JSON.parse(res).name) // => 'then-callback'
})
15 changes: 15 additions & 0 deletions examples/rejected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*!
* then-callback <https://github.com/hybridables/then-callback>
*
* Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/

'use strict'

var thenCallback = require('../index')
var NativePromise = require('native-or-another')()

// rejected promise
var promise = NativePromise.reject(new Error('foo bar'))
thenCallback(promise).then(console.log, console.error) // => Error: foo bar
15 changes: 15 additions & 0 deletions examples/resolved.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*!
* then-callback <https://github.com/hybridables/then-callback>
*
* Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/

'use strict'

var thenCallback = require('../index')
var NativePromise = require('native-or-another')()

// resolved promise
var promise = NativePromise.resolve(123)
thenCallback(promise).then(console.log, console.error) // => '123'
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"devDependencies": {
"assertit": "^0.1.0",
"native-or-another": "^3.0.1"
"native-or-another": "^3.0.1",
"redolent": "^1.0.3"
},
"files": [
"index.js"
Expand Down

0 comments on commit 056c828

Please sign in to comment.