Skip to content

Instantly share code, notes, and snippets.

@mmasiukevich
Created May 15, 2019 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmasiukevich/c2eb86974cc0a0b2787734e0196d6ec2 to your computer and use it in GitHub Desktop.
Save mmasiukevich/c2eb86974cc0a0b2787734e0196d6ec2 to your computer and use it in GitHub Desktop.
    public function someMethod(DatabaseAdapter $adapter): Promise
    {
        return call(
            static function() use ($adapter): \Generator
            {
                /** @var \ServiceBus\Storage\Common\Transaction $transaction */
                $transaction = yield $adapter->transaction();
                
                try {

                    yield $transaction->execute('SELECT NOW()');
                    
                    yield $transaction->commit();
                }catch(\Throwable $throwable){
                    yield $transaction->rollback();
                }
            }
        );
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment