Add support for promises in when clause