Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PrsJs

A simple implementation of Promise pattern for JavaScript

				function request(url) {
					return new Promise(function(resolve, reject) {
						$.ajax({
							"url" : url,
							success : function(response) {
								resolve(response);
							},
							error : function(xhr, status, e) {
								reject(e);
							}
						})
					});
				}

				var requesta = request("/fun/test/hello");

				var requestc = request("/fun/test/world");

				Promise.map2(requesta, requestc, function(a, c) {
					return (a + "----" + c);
				}).on("success", function(x) {
					console.log(x);
				});

				var all = Promise.all([ requesta, requestc ]).on("success",
						function(x) {
							console.log(x);
						});

				var goodbye = all.flatMap(function(x) {
					console.log("after all return get >>>" + x);
					console.log("call goodBye");
					return request("/fun/test/goodbye");
				});

				goodbye.on("success", function(x) {
					console.log("goodbye ? >>>" + x);
				});

				var fd = Promise.foldLeft([ requesta, requestc, goodbye ], [],
						function(array, x) {
							array.push(x);
							return array;
						});
				fd.on("success", function(x) {
					console.log("foldLeft called get >>>" + x);
				});

About

A simple implementation of Promise pattern for JavaScript

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages