Skip to content

Instantly share code, notes, and snippets.

@juniorb2ss
Last active January 24, 2017 00:03
Show Gist options
  • Select an option

  • Save juniorb2ss/c1e98dd5cf5d09321e72fdf1bc211978 to your computer and use it in GitHub Desktop.

Select an option

Save juniorb2ss/c1e98dd5cf5d09321e72fdf1bc211978 to your computer and use it in GitHub Desktop.

Revisions

  1. juniorb2ss revised this gist Jan 24, 2017. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions promise.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    'use strict';

    var Promise = require('bluebird');
    @@ -10,14 +9,14 @@ if (typeof Promise === 'undefined') {
    }


    var getUserAsync = Promise.method(function(options){
    return new Promise(function(resolve,reject){

    setTimeout(function(){ resolve('getUserAsync Function')}, 3000);
    var getUserAsync = Promise.method(function(event, context, callback){
    return new Promise(function(resolve, reject){
    setTimeout(function(){ resolve(getUser(event, context, callback))}, 3000);
    });
    });

    function getUser(event, context, callback){
    console.log(event);
    return 'getUser Function Promisse';
    }

  2. juniorb2ss created this gist Jan 23, 2017.
    33 changes: 33 additions & 0 deletions promise.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@

    'use strict';

    var Promise = require('bluebird');
    var AWS = require('aws-sdk');

    // Check if environment supports native promises
    if (typeof Promise === 'undefined') {
    AWS.config.setPromisesDependency(require('bluebird'));
    }


    var getUserAsync = Promise.method(function(options){
    return new Promise(function(resolve,reject){

    setTimeout(function(){ resolve('getUserAsync Function')}, 3000);
    });
    });

    function getUser(event, context, callback){
    return 'getUser Function Promisse';
    }

    exports.handler = function (event, context, callback) {
    getUserAsync(event, context, callback).then( function (res) {
    console.log(res);
    })
    .catch(function(err){
    console.log('error');
    });
    };

    exports.handler([], null, function(){});