Skip to content

kimar/Promise.swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Promise.swift

Twitter: @Kidmar Carthage compatible License Build Status Xcode 8.2+ iOS 8.0+ Swift 3.0+

tl;dr

A very simple Swift 3.0 Promise library I've written while on the plane using my iPad and Playgrounds.

Writte in just 33 lines of code.

Usage

Rather simple and more for reference than actually to be used is this very simple implementation of a Promise framework.

Succeeding

Promise<String> { resolve, reject in 
	resolve("Bazingaaaa!")
}.then { result in 
	print(result) // Bazingaaaa!
}

Failing

Promise<String> { resolve, reject in 
	reject(Error.AnError)
}.fail { error in 
	print("An error occured \(error)")
}

Chaining

Promise<String> { resolve, reject in 
	resolve(1)
}.then { result -> Promise<Int> in 
	return Promise<Int> { resolve, reject in 
		resolve(result + 1)
	}
}.then { result -> Promise<Int> in 
	return Promise<Int> { resolve, reject in 
		resolve(result + 1)
	}
}.then { result in 
	print(result) // 3
}

Contributing

Please take a moment to read and understand the Berlin Code of Conduct.

License

See LICENSE.md

About

A tiny and simple Swift Promise library, written in 33 lines of code πŸ„β€β™‚οΈ

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages