I have a controller and a factory. A function(myfunc) inside the factory(searchFactory) is called by ng-click of a button. after which I call a function(waitfunction) which is outside the conntroller. In that function timeout of 2 sec is used and then a value is changed and returned to the controller. How can I make sure that the value is updated in the controller after 2 sec. JSfiddle : <http://jsfiddle.net/zohairzohair4/cRr9K/1334/>

```
var search_name  
var angularjsapp = angular.module('graphApp', ['ngAnimate', 'ui.bootstrap']);

angularjsapp.factory('searchFactory', function() {
  //return $resource('friends.json');
  return{
        myfunc:function(search_name){
            console.log('ok')
            keyword_type = 1
            loading_value = waitfunction(search_name)
            console.log(loading_value)
            return loading_value
            }
        }   
});

angularjsapp.controller('AccordionDemoCtrl', function($scope,searchFactory) {
    $scope.count = 0;
    $scope.namesPerPage = 10
    $scope.currentPage = 1;
    $scope.searchFactory = searchFactory.myfunc 
});

function waitfunction(search_name){
            value = 0
            window.setTimeout(function () {
                        value = 1;
                    }, 2000);
            return value        
        };

```